xml - Counting in XSL:FO -


i have 2 expressions, , want put them in same table , count them have this:

1.  replacement 1 2.  replacement 2 3.  replacement 3 4.  repair 1 5.  repair 2 6.  repair 3 

but i'm getting output:

1.  replacement 1 2.  replacement 2 3.  replacement 3 1.  repair 1 2.  repair 2 3.  repair 3 

xml

<selectedcalculation>     <classxml>         <calcdata>             <rundesc>normalcalc</rundesc>             <spareparts>                <partdtls>                   <partdtl>                       <reptyp>e</reptyp>                        <gid>0281</gid>                        <partdesc>replacement 1</partdesc>                        <partno>8w0 807 065 gru</partno>                        <price cur="hrk">+3002.92</price>                    </partdtl>                   <partdtl>                       <reptyp>e</reptyp>                        <gid>0297</gid>                        <partdesc>replacement 2</partdesc>                        <partno>8w0 807 681 b 9b9</partno>                        <price cur="hrk">+193.01</price>                    </partdtl>                   <partdtl>                       <reptyp>e</reptyp>                        <gid>0410</gid>                        <partdesc>reŠetka hladnjaka</partdesc>                        <partno>8w0 853 651 3fz</partno>                        <price cur="hrk">+1640.57</price>                   </partdtl>                </partdtls>             </spareparts>             <labor>                <idtls>                   <idtl>                       <reptyp>i</reptyp>                        <gid>0471</gid>                        <partdesc>repair 1</partdesc>                        <repdesc>popravak</repdesc>                    </idtl>                   <idtl>                       <reptyp>i</reptyp>                        <gid>0741</gid>                        <partdesc>repair 2</partdesc>                        <repdesc>popravak</repdesc>                    </idtl>                   <idtl>                       <reptyp>i</reptyp>                        <gid>0742</gid>                        <partdesc>repair 3</partdesc>                        <repdesc>popravak</repdesc>                    </idtl>                </idtls>             </labor>         </calcdata> </selectedcalculation> 

xslt

<xsl:template name="standardparts">   <xsl:for-each select="selectedcalculation//calcdata[rundesc = 'normalcalc']//spareparts[1]//partdtl">     <xsl:variable name="detal" select="gid"/>     <fo:table-row>       <fo:table-cell>         <fo:block text-align="left">           <xsl:value-of select="position()"/>           <xsl:value-of select="'. '"/>           <xsl:value-of select="partdesc"/>         </fo:block>       </fo:table-cell>     </fo:table-row>     </xsl:for-each>      <xsl:for-each select="selectedcalculation//calcdata[rundesc = 'normalcalc']//idtl">       <xsl:variable name="detal" select="gid"/>       <fo:table-row>         <fo:table-cell>           <fo:block text-align="left" >             <xsl:value-of select="position()"/>             <xsl:value-of select="'. '"/>             <xsl:value-of select="partdesc"/>             </fo:block>         </fo:table-cell>       </fo:table-row>     </xsl:for-each> </xsl:template> 

you should use xsl:number instead of position(). position() function returns number equal context position. xsl:number element provides more functionality.

i'd suggest replacing named template 2 xsl:for-each xsl:apply-templates , adding single template match both partdtl , idtl.

example...

xml input (modified because input isn't well-formed. calcdata child sibling of classxml? made child wrote xslt work either way.)

<selectedcalculation>     <classxml>         <calcdata>             <rundesc>normalcalc</rundesc>             <spareparts>                 <partdtls>                     <partdtl>                         <reptyp>e</reptyp>                          <gid>0281</gid>                          <partdesc>replacement 1</partdesc>                          <partno>8w0 807 065 gru</partno>                          <price cur="hrk">+3002.92</price>                      </partdtl>                     <partdtl>                         <reptyp>e</reptyp>                          <gid>0297</gid>                          <partdesc>replacement 2</partdesc>                          <partno>8w0 807 681 b 9b9</partno>                          <price cur="hrk">+193.01</price>                      </partdtl>                     <partdtl>                         <reptyp>e</reptyp>                          <gid>0410</gid>                          <partdesc>reŠetka hladnjaka</partdesc>                          <partno>8w0 853 651 3fz</partno>                          <price cur="hrk">+1640.57</price>                     </partdtl>                 </partdtls>             </spareparts>             <labor>                 <idtls>                     <idtl>                         <reptyp>i</reptyp>                          <gid>0471</gid>                          <partdesc>repair 1</partdesc>                          <repdesc>popravak</repdesc>                      </idtl>                     <idtl>                         <reptyp>i</reptyp>                          <gid>0741</gid>                          <partdesc>repair 2</partdesc>                          <repdesc>popravak</repdesc>                      </idtl>                     <idtl>                         <reptyp>i</reptyp>                          <gid>0742</gid>                          <partdesc>repair 3</partdesc>                          <repdesc>popravak</repdesc>                      </idtl>                 </idtls>             </labor>         </calcdata>     </classxml> </selectedcalculation> 

xslt 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:fo="http://www.w3.org/1999/xsl/format">   <xsl:output indent="yes"/>   <xsl:strip-space elements="*"/>    <xsl:template match="/">     <fo:root>       <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 select="selectedcalculation"/>         </fo:flow>       </fo:page-sequence>     </fo:root>   </xsl:template>    <xsl:template match="selectedcalculation">     <fo:table>       <fo:table-body>         <xsl:apply-templates select=".//calcdata[rundesc='normalcalc']//*[self::partdtl or self::idtl]"/>       </fo:table-body>     </fo:table>   </xsl:template>    <xsl:template match="partdtl|idtl">     <fo:table-row>       <fo:table-cell>         <fo:block text-align="left">           <xsl:number count="partdtl[ancestor::calcdata[rundesc='normalcalc']]|             idtl[ancestor::calcdata[rundesc='normalcalc']]"              level="any" format="1. "/>           <xsl:value-of select="partdesc"/>         </fo:block>       </fo:table-cell>     </fo:table-row>   </xsl:template>  </xsl:stylesheet> 

xsl-fo output

<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:table>             <fo:table-body>                <fo:table-row>                   <fo:table-cell>                      <fo:block text-align="left">1. replacement 1</fo:block>                   </fo:table-cell>                </fo:table-row>                <fo:table-row>                   <fo:table-cell>                      <fo:block text-align="left">2. replacement 2</fo:block>                   </fo:table-cell>                </fo:table-row>                <fo:table-row>                   <fo:table-cell>                      <fo:block text-align="left">3. reŠetka hladnjaka</fo:block>                   </fo:table-cell>                </fo:table-row>                <fo:table-row>                   <fo:table-cell>                      <fo:block text-align="left">4. repair 1</fo:block>                   </fo:table-cell>                </fo:table-row>                <fo:table-row>                   <fo:table-cell>                      <fo:block text-align="left">5. repair 2</fo:block>                   </fo:table-cell>                </fo:table-row>                <fo:table-row>                   <fo:table-cell>                      <fo:block text-align="left">6. repair 3</fo:block>                   </fo:table-cell>                </fo:table-row>             </fo:table-body>          </fo:table>       </fo:flow>    </fo:page-sequence> </fo:root> 

rendered pdf (used fop 1.1)

enter image description here

for example, here 2 replacement templates create actual list instead of table. (note space removed in format attribute.) rendered pdf looks same above.

<xsl:template match="selectedcalculation">   <fo:list-block provisional-distance-between-starts="24pt"     space-before=".1in" space-after=".1in">     <xsl:apply-templates select=".//calcdata[rundesc='normalcalc']//*[self::partdtl or self::idtl]"/>   </fo:list-block> </xsl:template>  <xsl:template match="partdtl|idtl">   <fo:list-item>     <fo:list-item-label end-indent="label-end()">       <fo:block>         <xsl:number count="partdtl[ancestor::calcdata[rundesc='normalcalc']]|           idtl[ancestor::calcdata[rundesc='normalcalc']]"            level="any" format="1."/>       </fo:block>     </fo:list-item-label>     <fo:list-item-body start-indent="body-start()">       <fo:block>         <xsl:value-of select="partdesc"/>       </fo:block>     </fo:list-item-body>   </fo:list-item> </xsl:template> 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -