XSL-FO 中的步骤编号
Step numbering in XSL-FO
为此苦苦挣扎了一段时间,现在要寻求帮助。当使用 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 样式表。感谢任何帮助,提前致谢。
//isolationStep
正在选择文档中的每个 isolationStep
,因此您将获得每个
的编号。
您可能一直在尝试获得“//isolationStep[@id=$ref] | //isolationProcedureEnd[@id=$ref]
的效果,但您最好使用密钥通过其 ID 查找 isolationStep
和 isolationProcedureEnd
.
键定义在 http://www.w3.org/TR/xslt20/#key
您可以将 isolationStep
元素的 @id
查找键定义为样式表中的顶级元素:
<xsl:key name="isolationSteps"
match="isolationStep"
use="@id" />
并在您的模板中,使用 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>
为此苦苦挣扎了一段时间,现在要寻求帮助。当使用 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 样式表。感谢任何帮助,提前致谢。
//isolationStep
正在选择文档中的每个 isolationStep
,因此您将获得每个
您可能一直在尝试获得“//isolationStep[@id=$ref] | //isolationProcedureEnd[@id=$ref]
的效果,但您最好使用密钥通过其 ID 查找 isolationStep
和 isolationProcedureEnd
.
键定义在 http://www.w3.org/TR/xslt20/#key
您可以将 isolationStep
元素的 @id
查找键定义为样式表中的顶级元素:
<xsl:key name="isolationSteps"
match="isolationStep"
use="@id" />
并在您的模板中,使用 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>