Repeat header when NODE changes (compare with previous-sibling)

Reply

Join Date: Sep 2008
Posts: 1
Reputation: qwix123 is an unknown quantity at this point 
Solved Threads: 0
qwix123 qwix123 is offline Offline
Newbie Poster

Repeat header when NODE changes (compare with previous-sibling)

 
0
  #1
Sep 16th, 2008
Hello,
this is my XML:
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <OPTIONS>
  2.  
  3. <ROW NUM="1">
  4. <ROW_NUM>1</ROW_NUM>
  5. <INVOICE_NUMBER>000001</INVOICE_NUMBER>
  6. <ID>144795</ID>
  7. <CUS_UK>20544</CUS_UK>
  8. <DESC_LONG>KELEME</DESC_LONG>
  9. </ROW>
  10.  
  11. <ROW NUM="2">
  12. <ROW_NUM>1</ROW_NUM>
  13. <INVOICE_NUMBER>000001</INVOICE_NUMBER>
  14. <ID>69449</ID>
  15. <CUS_UK>15249</CUS_UK>
  16. <DESC_LONG>PETRIMEX</DESC_LONG>
  17. </ROW>
  18.  
  19. <ROW NUM="3">
  20. <ROW_NUM>1</ROW_NUM>
  21. <INVOICE_NUMBER>000001</INVOICE_NUMBER>
  22. <ID>4125</ID>
  23. <CUS_UK>15249</CUS_UK>
  24. <DESC_LONG>PETRIMEX</DESC_LONG>
  25. </ROW>
  26.  
  27. <ROW NUM="4">
  28. <ROW_NUM>3</ROW_NUM>
  29. <INVOICE_NUMBER>000002</INVOICE_NUMBER>
  30. <ID>4152</ID>
  31. <CUS_UK>15249</CUS_UK>
  32. <DESC_LONG>PETRIMEX</DESC_LONG>
  33. </ROW>
  34.  
  35. <ROW NUM="5">
  36. <ROW_NUM>3</ROW_NUM>
  37. <INVOICE_NUMBER>000002</INVOICE_NUMBER>
  38. <ID>69486</ID>
  39. <CUS_UK>15249</CUS_UK>
  40. <DESC_LONG>PETRIMEX</DESC_LONG>
  41. </ROW>
  42. </OPTIONS>

What I need to do is repeat some header everytime ROW_NUM changes. I came this far:
<xsl:for-each select="OPTIONS/ROW">
  <xsl:choose>
    <xsl:when test="position()=1 or preceding-sibling::ROW_NUM/text()[1] != ./ROW_NUM/text()">
        <!-- this should match the first row and then every row where ROW_NUM is different form previous -->
   </xsl:when>
   <xsl:otherwise>
     <!-- this should match the rest -->
   <xsl:otherwise>
 </xsl:choose>
</xsl:for-each>
I'm having trouble with writing the condition in red. Can someone give me an advice?
Thanks a lot!
Last edited by qwix123; Sep 16th, 2008 at 5:34 am. Reason: mistype
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 14
Reputation: gravyboat is an unknown quantity at this point 
Solved Threads: 2
gravyboat gravyboat is offline Offline
Newbie Poster

Re: Repeat header when NODE changes (compare with previous-sibling)

 
0
  #2
Sep 18th, 2008
See this: http://www.dpawson.co.uk/xsl/sect2/N6280.html#d9988e142 and this:http://www.dpawson.co.uk/xsl/sect2/N6461.html

Note that you can do some more efficient (and easier) sorting if you can use XSLT 2.0 using xsl-for-each-group() ; check out the "Sorting" and "Grouping" topics here: http://www.dpawson.co.uk/xsl/rev2/rev2.html
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the XML, XSLT and XPATH Forum


Views: 1870 | Replies: 1
Thread Tools Search this Thread



Tag cloud for XML, XSLT and XPATH
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC