2
XML:如何重號過濾元件設置
<?xml version="1.0" encoding="utf-8"?>
<book>
<chapter>
<section name="a">...</section>
<section name="b">...</section>
<section name="c">...</section>
<section name="d">...</section>
<section name="e">...</section>
...
</chapter>
<appendix>
<section name="reference">...</section>
</appendix>
</book>
您好,我想輸出的所有sections
下chapter
和appendix
節點。附錄中的部分將被打印出來。但是並不是所有章節都允許打印出,它們依賴於一些外部條件(如果段名在允許從java應用程序中傳入的列表中)。
而且sections
chapter
下應與正確序列號輸出前部分的名稱看起來像下面這樣:
期望的結果
- b ...
- d .. 。
(這意味着部分a,c,e被過濾掉)
我的問題是我如何能夠產生//chapter/section
以上所需的輸出?任何提示或幫助是高度讚賞
我的XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://example.com/namespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="validChapters" />
<xsl:function name="ex:isValidChapter" as="xs:boolean">
<xsl:param name="str-in" as="xs:string"/>
<xsl:choose>
<xsl:when test="contains($validChapters, $str-in)">
<xsl:sequence select="true()" />
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="false()" />
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template match="/">
<xsl:apply-templates select="chapter" />
<xsl:apply-templates select="appendix" />
</xsl:template>
<xsl:template match="chapter">
...
<xsl:apply-templates select="section" />
</xsl:template>
<xsl:template match="appendix">
...
<xsl:apply-templates select="section" />
</xsl:template>
<xsl:template match="section">
...
<xsl:apply-templates />
</xsl:template>
<xsl:template match="//chapter/section">
<xsl:if test="ex:isValidChapter(@name)">
<fo:block>
<xsl:number format="1."/>
<xsl:value-of select="@name" />
</fo:block>
<xsl:apply-templates />
</xsl:if>
</xsl:template>
...
</xsl:stylesheet>
用示例XML數據和所需輸出解釋更清楚。 –
「允許列表」存儲在哪裏? –
允許列表從java應用程序傳入,並以逗號分隔字符串的形式使用包含函數 –