一直苦苦挣扎,现在要求帮助。我正在尝试获取正确的数字,以便在使用XSL-FO时在PDF输出上引用它时显示一个步骤。在之前得到的帮助下,我有其他参考工作。这些特殊标签给我带来了麻烦。
这是针对S1000D航空航天出版物规范中的故障隔离树:
<isolationStep id="step4"><isolationStepQuestion>Check for burnt-out lamps. Are lamps good?</isolationStepQuestion><isolationStepAnswer><yesNoAnswer><yesAnswer nextActionRefId="step6"/><noAnswer nextActionRefId="step8"/></yesNoAnswer></isolationStepAnswer></isolationStep>
正如您所看到的,该问题有一个答案部分。这些答案已经适用于其他步骤。在PDF中我得到了正确编号的步骤,但在渲染答案时我得到了这个:
XSL-FO用于问题,答案以及尝试编号来回答引用的步骤:
<xsl:template match="isolationStep | isolationProcedureEnd">
<xsl:for-each select="note">
<fo:block font-weight="bold">Note</fo:block>
<xsl:apply-templates/>
</xsl:for-each>
<xsl:for-each select="caution">
<fo:block font-weight="bold" text-align="center">CAUTION</fo:block>
<xsl:apply-templates/>
</xsl:for-each>
<xsl:for-each select="warning">
<fo:block font-weight="bold" text-align="center">WARNING</fo:block>
<xsl:apply-templates/>
</xsl:for-each>
<fo:block id="{@id}" padding="5pt" font-size="10pt">
<!-- border-style="solid"
border-width=".1mm"-->
<!--<xsl:apply-templates/>-->
<fo:list-block space-after="2mm">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
<xsl:number level="multiple" count="isolationMainProcedure/isolationStep | isolationProcedureEnd" format="1."/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<!--<xsl:apply-templates select="title"/>-->
<xsl:choose>
<xsl:when test="count(action) > 1">
<xsl:for-each select="action">
<fo:list-block space-after="2mm">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
<xsl:number format="a."/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<!--<xsl:apply-templates/>-->
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="action">
<fo:block>
<xsl:apply-templates/>
</fo:block>
<!--<xsl:apply-templates/>-->
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="isolationStepQuestion"/>
<xsl:apply-templates select="isolationStepAnswer"/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</xsl:template>
<xsl:template match="isolationStep | isolationProcedureEnd" mode="nbr">
<xsl:variable name="origNbr">
<xsl:number level="multiple" format="1"/>
</xsl:variable>
<xsl:value-of select="$origNbr"/>
</xsl:template>
<xsl:template match="isolationStepQuestion">
<fo:block font-weight="bold">
<xsl:value-of select="."/>
</fo:block>
</xsl:template>
<xsl:template match="yesNoAnswer">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="yesAnswer">
<xsl:variable name="ref" select="@nextActionRefId"/>
<fo:block space-before="4pt" space-after="4pt" keep-with-previous="always">
<fo:inline><xsl:text>Yes: Go to </xsl:text>
<fo:basic-link internal-destination="{@nextActionRefId}" color="blue">Step <!--<xsl:value-of select="$yesref2"/>-->
<!--ancestor::isolationMainProcedure-->
<!--<xsl:apply-templates select="an../../../.././isolationStep | isolationProcedureEnd[@id=$yesref]" mode="nbr"/> ancestor::isolationMainProcedure[1]/-->
<xsl:apply-templates select="//isolationStep | isolationProcedureEnd[@id=$ref]" mode="nbr"/>
</fo:basic-link></fo:inline>
</fo:block>
</xsl:template>
<xsl:template match="noAnswer">
<xsl:variable name="ref" select="@nextActionRefId"/>
<fo:block keep-with-previous="always">
<fo:inline>
<xsl:text>No: Go to </xsl:text>
<fo:basic-link internal-destination="{@nextActionRefId}" color="blue">Step
<xsl:apply-templates select="//isolationStep | isolationProcedureEnd[@id=$ref]" mode="nbr"/>
</fo:basic-link></fo:inline>
</fo:block>
</xsl:template>
<xsl:template match="isolationStepAnswer">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="isolationStep | isolationProcedureEnd" mode="nbr">
<xsl:variable name="origNbr">
<xsl:number level="multiple" format="1"/>
</xsl:variable>
<xsl:value-of select="$origNbr"/>
</xsl:template>
此外,链接正常工作,并将您带到正确的位置。我正好让它正确编号。
这是一个XSL 2.0样式表。感谢任何帮助,提前谢谢。
答案 0 :(得分:2)
//isolationStep
正在选择文档中的每个isolationStep
,因此您需要获取每个//isolationStep[@id=$ref] | //isolationProcedureEnd[@id=$ref]
的数量。
您可能一直试图获得&#34; isolationStep
的效果,但您可能更善于使用密钥查找isolationProcedureEnd
和isolationStep
按他们的ID。
密钥在http://www.w3.org/TR/xslt20/#key
定义您可以定义一个键,用@id
元素查找<xsl:key name="isolationSteps"
match="isolationStep"
use="@id" />
元素作为样式表中的顶级元素:
key()
在您的模板中,使用isolationStep
功能查找匹配@id
值的<xsl:template match="yesAnswer">
<xsl:variable name="ref" select="@nextActionRefId"/>
<fo:block space-before="4pt" space-after="4pt" keep-with-previous="always">
<fo:inline><xsl:text>Yes: Go to </xsl:text>
<fo:basic-link internal-destination="{@nextActionRefId}" color="blue">Step <!--<xsl:value-of select="$yesref2"/>-->
<!--ancestor::isolationMainProcedure-->
<!--<xsl:apply-templates select="an../../../.././isolationStep | isolationProcedureEnd[@id=$yesref]" mode="nbr"/> ancestor::isolationMainProcedure[1]/-->
<xsl:apply-templates select="key('isolationSteps', $ref)" mode="nbr"/>
</fo:basic-link></fo:inline>
</fo:block>
</xsl:template>
:
{{1}}