2013-03-16 166 views
0

在xsl fo中,我需要使用xsl:number來標記/計算一個名爲prcitem1的元素,但我只想將prcitem1元素的第二個子元素命名爲paraxsl:number - 排除某些元素

編號的工作原理是唯一標記的元素是我剛剛描述的元素,但如果prcitem1元素不符合條件,即使標籤未顯示,它仍會計數。這會導致編號不正確,就像它將從B開始而不是A開始,因爲第一個prcitem1元素不符合標準,但仍然計數。我正在使用<xsl:number count="self::*[./prcitem1/para] format="A" from="task"。任務是prcitem1的包含元素,我從prcitem1模板中計算。任何人都知道如何處理這個?

+0

你對ATA手冊的工作?只是好奇。 – 2013-03-17 01:26:12

回答

0

你應該只算prcitem1[para]這樣的:

<xsl:number format="A" from="task" count="prcitem1[para]"/> 

下面是一個例子。它可能不完全匹配你的,而應該是關閉...

XML輸入

<doc> 
    <task> 
     <prclist1> 
      <prcitem1> 
       <prcitem> 
        <para>prcitem 1A</para> 
       </prcitem> 
      </prcitem1> 
      <prcitem1> 
       <prcitem> 
        <para>prcitem 2A</para> 
       </prcitem> 
      </prcitem1> 
      <prcitem1/> 
      <prcitem1> 
       <prcitem> 
        <para>prcitem 4A</para> 
       </prcitem> 
      </prcitem1> 
     </prclist1> 
     <prclist1> 
      <prcitem1> 
       <prcitem> 
        <para>prcitem 1B</para> 
       </prcitem> 
      </prcitem1> 
      <prcitem1/> 
      <prcitem1> 
       <prcitem> 
        <para>prcitem 3B</para> 
       </prcitem> 
      </prcitem1> 
      <prcitem1> 
       <prcitem> 
        <para>prcitem 4B</para> 
       </prcitem> 
      </prcitem1> 
     </prclist1> 
    </task> 
</doc> 

XSLT 2.0(會爲1.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="doc"> 
     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
      <fo:layout-master-set> 
       <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in"> 
        <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/> 
       </fo:simple-page-master> 
      </fo:layout-master-set> 
      <fo:page-sequence master-reference="my-page"> 
       <fo:flow flow-name="xsl-region-body"> 
        <xsl:apply-templates/> 
       </fo:flow> 
      </fo:page-sequence> 
     </fo:root> 
    </xsl:template> 

    <xsl:template match="prclist1"> 
     <fo:list-block font-size="10pt" provisional-distance-between-starts="24pt" space-before=".1in" space-after=".1in" keep-with-next.within-page="always"> 
      <xsl:apply-templates/> 
     </fo:list-block> 
    </xsl:template> 

    <xsl:template match="prcitem1[prcitem/para]"> 
     <fo:list-item> 
      <fo:list-item-label end-indent="label-end()" font-size="12pt" font-weight="bold"> 
       <fo:block> 
        <xsl:number format="A" from="task" count="prcitem1[prcitem/para]"/> 
       </fo:block> 
      </fo:list-item-label> 
      <fo:list-item-body start-indent="body-start()" font-size="12pt"> 
       <fo:block> 
        <xsl:apply-templates select="prcitem/para"/> 
       </fo:block> 
      </fo:list-item-body> 
     </fo:list-item> 
    </xsl:template> 

</xsl:stylesheet> 

FO輸出

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <fo:layout-master-set> 
     <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in"> 
     <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/> 
     </fo:simple-page-master> 
    </fo:layout-master-set> 
    <fo:page-sequence master-reference="my-page"> 
     <fo:flow flow-name="xsl-region-body"> 
     <fo:list-block font-size="10pt" 
         provisional-distance-between-starts="24pt" 
         space-before=".1in" 
         space-after=".1in" 
         keep-with-next.within-page="always"> 
      <fo:list-item> 
       <fo:list-item-label end-indent="label-end()" font-size="12pt" font-weight="bold"> 
        <fo:block>A</fo:block> 
       </fo:list-item-label> 
       <fo:list-item-body start-indent="body-start()" font-size="12pt"> 
        <fo:block>prcitem 1A</fo:block> 
       </fo:list-item-body> 
      </fo:list-item> 
      <fo:list-item> 
       <fo:list-item-label end-indent="label-end()" font-size="12pt" font-weight="bold"> 
        <fo:block>B</fo:block> 
       </fo:list-item-label> 
       <fo:list-item-body start-indent="body-start()" font-size="12pt"> 
        <fo:block>prcitem 2A</fo:block> 
       </fo:list-item-body> 
      </fo:list-item> 
      <fo:list-item> 
       <fo:list-item-label end-indent="label-end()" font-size="12pt" font-weight="bold"> 
        <fo:block>C</fo:block> 
       </fo:list-item-label> 
       <fo:list-item-body start-indent="body-start()" font-size="12pt"> 
        <fo:block>prcitem 4A</fo:block> 
       </fo:list-item-body> 
      </fo:list-item> 
     </fo:list-block> 
     <fo:list-block font-size="10pt" 
         provisional-distance-between-starts="24pt" 
         space-before=".1in" 
         space-after=".1in" 
         keep-with-next.within-page="always"> 
      <fo:list-item> 
       <fo:list-item-label end-indent="label-end()" font-size="12pt" font-weight="bold"> 
        <fo:block>A</fo:block> 
       </fo:list-item-label> 
       <fo:list-item-body start-indent="body-start()" font-size="12pt"> 
        <fo:block>prcitem 1B</fo:block> 
       </fo:list-item-body> 
      </fo:list-item> 
      <fo:list-item> 
       <fo:list-item-label end-indent="label-end()" font-size="12pt" font-weight="bold"> 
        <fo:block>B</fo:block> 
       </fo:list-item-label> 
       <fo:list-item-body start-indent="body-start()" font-size="12pt"> 
        <fo:block>prcitem 3B</fo:block> 
       </fo:list-item-body> 
      </fo:list-item> 
      <fo:list-item> 
       <fo:list-item-label end-indent="label-end()" font-size="12pt" font-weight="bold"> 
        <fo:block>C</fo:block> 
       </fo:list-item-label> 
       <fo:list-item-body start-indent="body-start()" font-size="12pt"> 
        <fo:block>prcitem 4B</fo:block> 
       </fo:list-item-body> 
      </fo:list-item> 
     </fo:list-block> 
     </fo:flow> 
    </fo:page-sequence> 
</fo:root> 

PDF輸出

enter image description here