scopley Posted November 7, 2007 Share Posted November 7, 2007 I have written an XSL script and everything works great except the sorting. I need the data to sort by <prtnbr> but cannot accomplish this unless I remove 2 columns of required data that is generated by attributes.Here is a sample of the XML file: <chapter chapnbr="23" id="ch23"><section chapnbr="23" id="sc2320" sectnbr="20"><subject chapnbr="23" id="sj232000" sectnbr="20" subjnbr="00"><dpfigure chg="u" figcnt="10" id="sj23200010"><prtlist><prtrow><item>005</item><prtnbr>822-1071-001</prtnbr><qty>1</qty></prtrow><prtrow><item>010</item><prtnbr>372254-91</prtnbr><qty>1</qty></prtrow><prtrow><item>015</item><prtnbr>372254-93</prtnbr><qty>1</qty></prtrow><prtrow><item>020</item><prtnbr>622-4957-001</prtnbr><qty>1</qty></prtrow></prtlist></dpfigure></subject><subject chapnbr="23" id="sj232000" sectnbr="20" subjnbr="10"><dpfigure chg="u" figcnt="20" id="sj23200010"><prtlist><prtrow><item>105</item><prtnbr>1071-001</prtnbr><qty>1</qty></prtrow><prtrow><item>015</item><prtnbr>72254-91</prtnbr><qty>1</qty></prtrow><prtrow><item>025</item><prtnbr>3254-93</prtnbr><qty>1</qty></prtrow><prtrow><item>030</item><prtnbr>62-4957-001</prtnbr><qty>1</qty></prtrow></prtlist></dpfigure></subject><subject chapnbr="23" id="sj232000" sectnbr="20" subjnbr="20"><dpfigure chg="u" figcnt="30" id="sj23200010"><prtlist><prtrow><item>005</item><prtnbr>MK1071-001</prtnbr><qty>1</qty></prtrow><prtrow><item>010</item><prtnbr>54AB-91</prtnbr><qty>1</qty></prtrow><prtrow><item>015</item><prtnbr>3254-LO</prtnbr><qty>1</qty></prtrow><prtrow><item>020</item><prtnbr>JT-4957-001</prtnbr><qty>1</qty></prtrow></prtlist></dpfigure></subject></section></chapter> Here is part of the XSL file: <xsl:apply-templates select="//subject"> <xsl:sort select="prtnbr"></xsl:apply-templates><xsl:template match="subject"> <xsl:variable name="chsecsub"> <xsl:value-of select="@chapnbr"/> <xsl:text>-</xsl:text> <xsl:value-of select="@sectnbr"/> <xsl:text>-</xsl:text> <xsl:value-of select="@subjnbr"/> </xsl:variable> <xsl:for-each select="dpfigure"> <xsl:variable name="figcnt" select="@figcnt"/> <xsl:for-each select="prtlist/prtrow"> <fo:table-row> <fo:table-cell> <fo:block> <xsl:value-of select="prtnbr"/> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select="$chsecsub"/> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select="$figcnt"/> </fo:block> </fo:table-cell> <fo:table-cell text-align="center"> <fo:block> <xsl:value-of select="item"/> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select="qty"/> </fo:block> </fo:table-cell> </fo:table-row> </xsl:for-each> </xsl:for-each> </xsl:template> Here is the desired output: Part Number Ch/Sec/Sub Fig. Item Qty.1071-001 23-20-10 20 105 13254-93 23-20-10 20 025 13254-LO 23-20-20 30 015 1372254-91 23-20-00 10 010 1372254-93 23-20-00 10 015 154AB-91 23-20-20 30 010 1622-4957-001 23-20-00 10 020 1623-4957-001 23-20-10 20 030 172254-91 23-20-10 20 015 1822-1071-001 23-20-00 10 005 1JT-4957-001 23-20-20 30 020 1MK1071-001 23-20-20 30 005 1 Any help would be greatly appreciated as I have been struggling with this for several days now. Link to comment Share on other sites More sharing options...
scopley Posted November 7, 2007 Author Share Posted November 7, 2007 Problem has been solved by using the axes nodes. The following is a simplified version of the code: <xsl:template match="chapter"> <xsl:for-each select="descendant::prtrow"> <xsl:sort select="prtnbr" /> <row> <cell><xsl:value-of select="ancestor::chapter/@chapnbr"/></cell> <cell><xsl:value-of select="item"/></cell> <cell><xsl:value-of select="prtnbr"/></cell> <row> </xsl:for-each></xsl:template> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.