链接中的XSL-FO段落编号

时间:2014-11-14 19:37:37

标签: xml xslt xsl-fo

我正在生成S1000D xml的PDF,需要显示指向另一个步骤的链接,并给出步骤编号/字母指定。在下图中,当前显示为1.d的链接。应阅读1.c。

Current output

包含ref的源xml如下:

<mainProcedure>
<proceduralStep id="S0001">
    <para id="P0001">REMOVE COMPONENT XYZ.</para>
    <proceduralStep id="S0002">
        <para id="P0002">This is a second level procedural step.</para>
        <proceduralStep id="S0003">
            <para id="P0003">This is a third level procedural step.</para>
            <proceduralStep id="S0004">
                <para id="P0004">This is a fourth level procedural step.</para>
                <proceduralStep id="S0006">
                    <para id="P0006">This is a fifth level procedural step.</para>
                </proceduralStep>
            </proceduralStep>
        </proceduralStep>
    </proceduralStep>
    <proceduralStep id="S0005">
        <para id="P0005">This is a second, second level procedural step.</para>
    </proceduralStep>
    <proceduralStep id="S0008">
        <para id="P0008">The following sub-step has quantity data included.</para>
        <proceduralStep id="S0009">
            <para>Position bracket on frame and secure with bolts and washers. <emphasis
>TORQUE BOLT TO <quantity>
                        <quantityGroup quantityGroupType="minimum"
quantityUnitOfMeasure="ft.lbf">
                            <quantityValue>10</quantityValue>
                        </quantityGroup>
                        <quantityGroup quantityGroupType="maximum"
quantityUnitOfMeasure="ft.lbf">
                            <quantityValue>15</quantityValue>
                        </quantityGroup>
                    </quantity>
                </emphasis>.</para>
        </proceduralStep>
    </proceduralStep>
    <proceduralStep id="S0007">
        <para id="P0007">This is a para with a reference to <internalRef
internalRefId="S0008" internalRefTargetType="step"> another step</internalRef
> in the procedure.</para>
    </proceduralStep>
</proceduralStep>

这是我的XSL,它给了我不正确的数字/字母组合。它似乎是给我包含链接的步骤的编号(还有另一个处理<quantity>数据的模板:

<xsl:template match="internalRef[@internalRefTargetType='step']">
        <xsl:variable name="refId" select="./@internalRefId"/>
        <xsl:if test="//mainProcedure//proceduralStep/@id = $refId">
            <xsl:if test="//mainProcedure/proceduralStep/@id = $refId">
                <fo:inline>
                    <fo:basic-link internal-destination="{$refId}" color="blue" text-decoration="underline">
                        Step <xsl:number level="multiple" count="mainProcedure/proceduralStep" format="1."/>
                    </fo:basic-link>
                </fo:inline>
            </xsl:if>
            <xsl:if test="//mainProcedure/proceduralStep/proceduralStep/@id = $refId">
                <fo:inline>
                    <fo:basic-link internal-destination="{$refId}" color="blue" text-decoration="underline">
                        Step <xsl:number level="multiple" count="//mainProcedure/proceduralStep" format="1."/><xsl:number level="single" count="//mainProcedure/proceduralStep | proceduralStep" format="a."/>
                    </fo:basic-link>
                </fo:inline>
            </xsl:if>
        </xsl:if>
    </xsl:template>

非常感谢任何让我走上正确道路的帮助。

1 个答案:

答案 0 :(得分:2)

我认为你让xsl:number太复杂了。您应该只能使用一个xsl:number并删除xsl:if(通过执行xsl:apply-templates并使用模式模板)。

但是,我在format属性中遇到了与parens有关的问题,因此您可能需要对结果数进行一些额外的格式化。此外,您还必须添加fo:inline来为参考中的第5级步骤加下划线,但由于整个链接都有下划线,因此您永远不会看到它。

以下是我的想法的一个例子。这仅处理参考文献,仅供参考。

XML输入(在底部添加了其他参考资料)

<mainProcedure>
    <proceduralStep id="S0001">
        <para id="P0001">REMOVE COMPONENT XYZ.</para>
        <proceduralStep id="S0002">
            <para id="P0002">This is a second level procedural step.</para>
            <proceduralStep id="S0003">
                <para id="P0003">This is a third level procedural step.</para>
                <proceduralStep id="S0004">
                    <para id="P0004">This is a fourth level procedural step.</para>
                    <proceduralStep id="S0006">
                        <para id="P0006">This is a fifth level procedural step.</para>
                    </proceduralStep>
                </proceduralStep>
            </proceduralStep>
        </proceduralStep>
        <proceduralStep id="S0005">
            <para id="P0005">This is a second, second level procedural step.</para>
        </proceduralStep>
        <proceduralStep id="S0008">
            <para id="P0008">The following sub-step has quantity data included.</para>
            <proceduralStep id="S0009">
                <para>Position bracket on frame and secure with bolts and washers. <emphasis
                    >TORQUE BOLT TO <quantity>
                        <quantityGroup quantityGroupType="minimum"
                            quantityUnitOfMeasure="ft.lbf">
                            <quantityValue>10</quantityValue>
                        </quantityGroup>
                        <quantityGroup quantityGroupType="maximum"
                            quantityUnitOfMeasure="ft.lbf">
                            <quantityValue>15</quantityValue>
                        </quantityGroup>
                    </quantity>
                </emphasis>.</para>
            </proceduralStep>
        </proceduralStep>
        <proceduralStep id="S0007">
            <para id="P0007">This is a para with a reference to <internalRef
                internalRefId="S0008" internalRefTargetType="step"> another step</internalRef
                > in the procedure.</para>
            <para>This is a para with a reference to <internalRef
                internalRefId="S0001" internalRefTargetType="step"> another step</internalRef
                > in the procedure.</para>
            <para>This is a para with a reference to <internalRef
                internalRefId="S0002" internalRefTargetType="step"> another step</internalRef
                > in the procedure.</para>
            <para>This is a para with a reference to <internalRef
                internalRefId="S0003" internalRefTargetType="step"> another step</internalRef
                > in the procedure.</para>
            <para>This is a para with a reference to <internalRef
                internalRefId="S0004" internalRefTargetType="step"> another step</internalRef
                > in the procedure.</para>
            <para>This is a para with a reference to <internalRef
                internalRefId="S0005" internalRefTargetType="step"> another step</internalRef
                > in the procedure.</para>
            <para>This is a para with a reference to <internalRef
                internalRefId="S0006" internalRefTargetType="step"> another step</internalRef
                > in the procedure.</para>

        </proceduralStep>
    </proceduralStep>
</mainProcedure>

XSLT 2.0

<xsl:stylesheet version="2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="internalRef[@internalRefTargetType='step']">
        <xsl:variable name="refId" select="@internalRefId"/>
        <fo:inline>
            <fo:basic-link internal-destination="{$refId}" color="blue" 
                text-decoration="underline">
                <xsl:text>Step </xsl:text> 
                <xsl:apply-templates select="//proceduralStep[@id=$refId]" mode="nbr"/>
            </fo:basic-link>
        </fo:inline>    
    </xsl:template>

    <xsl:template match="proceduralStep" mode="nbr">
        <xsl:variable name="origNbr">
            <xsl:number level="multiple" format="1.a.1.a.1"/>            
        </xsl:variable>
        <xsl:for-each select="tokenize($origNbr,'\.')">
            <xsl:value-of select="if (position()=(3,4)) then concat('(',.,')') 
                else if (position()=5) then . else concat(.,'.')"/>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

XML输出

<mainProcedure>
   <proceduralStep id="S0001">
      <para id="P0001">REMOVE COMPONENT XYZ.</para>
      <proceduralStep id="S0002">
         <para id="P0002">This is a second level procedural step.</para>
         <proceduralStep id="S0003">
            <para id="P0003">This is a third level procedural step.</para>
            <proceduralStep id="S0004">
               <para id="P0004">This is a fourth level procedural step.</para>
               <proceduralStep id="S0006">
                  <para id="P0006">This is a fifth level procedural step.</para>
               </proceduralStep>
            </proceduralStep>
         </proceduralStep>
      </proceduralStep>
      <proceduralStep id="S0005">
         <para id="P0005">This is a second, second level procedural step.</para>
      </proceduralStep>
      <proceduralStep id="S0008">
         <para id="P0008">The following sub-step has quantity data included.</para>
         <proceduralStep id="S0009">
            <para>Position bracket on frame and secure with bolts and washers. <emphasis>TORQUE BOLT TO <quantity>
                     <quantityGroup quantityGroupType="minimum" quantityUnitOfMeasure="ft.lbf">
                        <quantityValue>10</quantityValue>
                     </quantityGroup>
                     <quantityGroup quantityGroupType="maximum" quantityUnitOfMeasure="ft.lbf">
                        <quantityValue>15</quantityValue>
                     </quantityGroup>
                  </quantity>
               </emphasis>.</para>
         </proceduralStep>
      </proceduralStep>
      <proceduralStep id="S0007">
         <para id="P0007">This is a para with a reference to <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format">
               <fo:basic-link internal-destination="S0008"
                              color="blue"
                              text-decoration="underline">Step 1.c.</fo:basic-link>
            </fo:inline> in the procedure.</para>
         <para>This is a para with a reference to <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format">
               <fo:basic-link internal-destination="S0001"
                              color="blue"
                              text-decoration="underline">Step 1.</fo:basic-link>
            </fo:inline> in the procedure.</para>
         <para>This is a para with a reference to <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format">
               <fo:basic-link internal-destination="S0002"
                              color="blue"
                              text-decoration="underline">Step 1.a.</fo:basic-link>
            </fo:inline> in the procedure.</para>
         <para>This is a para with a reference to <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format">
               <fo:basic-link internal-destination="S0003"
                              color="blue"
                              text-decoration="underline">Step 1.a.(1)</fo:basic-link>
            </fo:inline> in the procedure.</para>
         <para>This is a para with a reference to <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format">
               <fo:basic-link internal-destination="S0004"
                              color="blue"
                              text-decoration="underline">Step 1.a.(1)(a)</fo:basic-link>
            </fo:inline> in the procedure.</para>
         <para>This is a para with a reference to <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format">
               <fo:basic-link internal-destination="S0005"
                              color="blue"
                              text-decoration="underline">Step 1.b.</fo:basic-link>
            </fo:inline> in the procedure.</para>
         <para>This is a para with a reference to <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format">
               <fo:basic-link internal-destination="S0006"
                              color="blue"
                              text-decoration="underline">Step 1.a.(1)(a)1</fo:basic-link>
            </fo:inline> in the procedure.</para>
      </proceduralStep>
   </proceduralStep>
</mainProcedure>