我正在尝试创建多级列表输出。我使用 XML 1.0 中的 XSLT 通过 apache FOP 运行
我使用如下所示的 XML 输入,其中 procedureList 中有许多不同的过程,其中有许多步骤。子步骤嵌入在步骤中。
<ProcedureList>
<Procedure title="The First Procedure" type="Removal">
<Steps>
<Step id="1">Step 1 </Step>
<Step id="2">Step 2 </Step>
<Step id="3">Step 3 <Step id="4">Step 4 <Step id="5">Step 5 </Step></Step></Step>
</Steps>
</Procedure>
<Procedure title="The Second Procedure" type="removal">
<Steps>
<Step id="6">Step 6 </Step>
<Step id="7">Step 7 <Step id="8">Step 8</Step></Step>
</Steps>
</Procedure>
</ProcedureList>
之后的输出是
1. The First Procedure
1.1 Step 1
1.2 Step 2
1.3 Step 3
1.3.a Step 4
1.3.a.i Step 5
2. The Second Procedure
2.1 Step 6
2.2 Step 7
2.2.a Step 8
使用下面的内容,我接近正确的答案(位置作为前导数字传递到模板,具体取决于过程在文档中发生的位置。
<xsl:template match="Step">
<xsl:param name="position" />
<fo:block >
<xsl:apply-templates select="WCN" />
<xsl:if test="normalize-space(text()) != ''">
<fo:block text-indent='-15mm' start-indent='15mm' xsl:use-attribute-sets="BodyText" wrap-option="wrap" white-space="pre">
<xsl:if test="$position != ''">
<xsl:value-of select="$position"/><xsl:text>.</xsl:text>
</xsl:if>
<xsl:if test="$position = ''">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:number format="1.1.a.i.a.i" count="Step" level="multiple"/><xsl:text> </xsl:text><xsl:apply-templates select="text()"/></fo:block>
</xsl:if>
<xsl:apply-templates select="Step" />
</fo:block>
</xsl:template>
我遇到的问题是当我需要在文档的一个区域中使用两个相同类型的过程时。 我称模板为
<xsl:choose>
<xsl:when test="root/ProcedureList/Procedure[@type='inspection' or @type='repair'] != ''">
<xsl:for-each select="root/ProcedureList/Procedure[@type='inspection' or @type='repair']">
<xsl:apply-templates >
<xsl:with-param name="position" select="8" />
</xsl:apply-templates>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<fo:block xsl:use-attribute-sets="BodyText">Not Applicable</fo:block>
</xsl:otherwise>
</xsl:choose>
我得到类似的输出
1. The First Procedure
1.1 Step 1
1.2 Step 2
1.3 Step 3
1.3.a Step 4
1.3.a.i Step 5
1. The Second Procedure
1.1 Step 6
1.2 Step 7
1.2.a Step 8
改变一下
<xsl:number format="1.1.a.i.a.i" count="Step" level="multiple"/>
到
<xsl:number format="1.1.a.i.a.i" count="Procedure|Step" level="multiple"/>