[英]Step numbering in XSL-FO
Been struggling with this for a bit and now going to ask for help. 挣扎了一下,现在要寻求帮助。 I am trying to get the correct number for a step to appear when referencing it on PDF output when using XSL-FO.
我正在尝试获取正确的数字,以便使用XSL-FO在PDF输出上引用它时出现一个步骤。 With help previously gotten here I have other references working as desired.
在先前获得帮助的情况下,我可以根据需要使用其他参考。 These particular tags are giving me trouble.
这些特殊的标签给我带来麻烦。
This is for a fault isolation tree in the S1000D aerospace publication spec: 这是针对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>
As you can see there is an answer section for the question. 如您所见,有一个问题的答案部分。 Those answers have refIds to other steps.
这些答案引用了其他步骤。 In the PDF I am getting the steps to be numbered correctly, but when rendering the answers I am getting this:
在PDF中,我正在正确地编号步骤,但是在呈现答案时,我得到了这一点:
The XSL-FO used for the questions, answers, and the attempt to number to answer referenced steps: 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>
Also, the links are working, and takes you to the correct location. 另外,链接有效,并带您到正确的位置。 I just am having issues getting it to number correctly.
我只是遇到问题,无法正确编号。
This is an XSL 2.0 stylesheet. 这是XSL 2.0样式表。 Any help is appreciated, thanks in advance.
任何帮助表示赞赏,在此先感谢。
The //isolationStep
is selecting every isolationStep
in the document, so you're getting the number of each of them. //isolationStep
正在选择文档中的每个isolationStep
,因此您将获得它们的数量。
You might have been trying to have the effect of " //isolationStep[@id=$ref] | //isolationProcedureEnd[@id=$ref]
, but you'd probably be better of using a key for looking up isolationStep
and isolationProcedureEnd
by their IDs. 您可能一直在尝试实现“
//isolationStep[@id=$ref] | //isolationProcedureEnd[@id=$ref]
,但是最好使用一个键来查找isolationStep
和isolationProcedureEnd
根据他们的ID。
Keys are defined at http://www.w3.org/TR/xslt20/#key 密钥在http://www.w3.org/TR/xslt20/#key中定义
You could define a key for lookup of isolationStep
elements by their @id
as a top-level element in the stylesheet: 您可以通过其
@id
定义一个用于查找isolationStep
元素的键,作为样式表中的顶级元素:
<xsl:key name="isolationSteps"
match="isolationStep"
use="@id" />
and in your template, use the key()
function to find the isolationStep
with the matching @id
value: 并在您的模板中,使用
key()
函数找到具有匹配@id
值的isolationStep
:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.