Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2006, 03:57 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inproper behaviour of preceding-sibling

Following are XML, XSL and Result.
If you observe closely, the behaviour of preceding-sibling is not working properly..Seq=4 is missing in the result(see bottom). can anyone please fix this problem?

XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<DATAEXPRESS>
 <DealerCommissions>
  <DealerCommission Seq="5">
   <Investment DocID="764548" StartOffset="90690">2000000</Investment>
   <Percentage DocID="764548" StartOffset="90643">0.80</Percentage>
  </DealerCommission>
  <DealerCommission Seq="6">
   <Investment DocID="764548" StartOffset="90717">3000000</Investment>
   <Percentage DocID="764548" StartOffset="90701">0.64</Percentage>
  </DealerCommission>
  <DealerCommission Seq="7">
   <Investment DocID="764548" StartOffset="90744">50000000</Investment>
   <Percentage DocID="764548" StartOffset="90728">0.40</Percentage>
  </DealerCommission>
  <DealerCommission Seq="8">
   <Investment DocID="764548" StartOffset="90773">100000000</Investment>
   <Percentage DocID="764548" StartOffset="90756">0.20</Percentage>
  </DealerCommission>
  <DealerCommission Seq="9">
   <Investment DocID="764548" StartOffset="90795">999999999</Investment>
   <Percentage DocID="764548" StartOffset="90789">0.12</Percentage>
  </DealerCommission>
  <DealerCommission Seq="0">
   <Investment DocID="766378" StartOffset="242761">49999</Investment>
   <Percentage DocID="766378" StartOffset="243057">4.00</Percentage>
  </DealerCommission>
  <DealerCommission Seq="1">
   <Investment DocID="766378" StartOffset="243157">99999</Investment>
   <Percentage DocID="766378" StartOffset="243400">3.00</Percentage>
  </DealerCommission>
  <DealerCommission Seq="2">
   <Investment DocID="766378" StartOffset="243519">249999</Investment>
   <Percentage DocID="766378" StartOffset="243816">2.25</Percentage>
  </DealerCommission>
  <DealerCommission Seq="3">
   <Investment DocID="766378" StartOffset="243917">499999</Investment>
   <Percentage DocID="766378" StartOffset="244160">1.25</Percentage>
  </DealerCommission>
  <DealerCommission Seq="4">
   <Investment DocID="766378" StartOffset="244279">999999</Investment>
   <Percentage DocID="766378" StartOffset="244578">0.80</Percentage>
  </DealerCommission>
 </DealerCommissions>
</DATAEXPRESS>

XSL:

       <xsl:for-each select="DATAEXPRESS/DealerCommissions/DealerCommission">
         <xsl:sort select="@Seq" data-type="number"/>
        <tr>
       <td>
           <xsl:value-of select="preceding-sibling::node()[position()=1]/Investment"/>
       </td>
       </tr>
     </xsl:for-each>


Result:

999999999
49999
99999
249999
499999

2000000
3000000
50000000
100000000


__________________
Rams
 
Old June 9th, 2006, 04:17 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The behaviour is exactly what you would expect. Seq=4 is the last node, so it is not the preceding sibling of any other node, so if you only select nodes that are preceding siblings, you're not going to select it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 9th, 2006, 04:24 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your quick response.

seq=4 is not the last node..if you observe we are using sort method in xsl, so seq=9 is the last node..It should generate output like following

49999
99999
249999
499999
999999
2000000
3000000
50000000
100000000

but its not generating like this? Could you please verify this?



 
Old June 9th, 2006, 04:31 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorting does not move nodes to a different place in the tree: it only causes them to be processed in a particular order. The parents, children, and siblings of a node are unaffected by sorting.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 9th, 2006, 04:36 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I appreciate your quick responses and thanks for letting me know about how sorting feature works.
Could you please tell, is there a way to display output like following?
49999
99999
249999
499999
999999
2000000
3000000
50000000
100000000


 
Old June 9th, 2006, 04:42 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually i want to disply the current node and as well as previous.
example:

0(hard code) - 49999
49999(previous sibling) - 99999(current node)
99999(previous sibling) - 249999(current node)

i am gettin the current node correctly..the problem is with previous.

see my current proj output:
       <xsl:for-each select="DATAEXPRESS/DealerCommissions/DealerCommission">
         <xsl:sort select="@Seq" data-type="number"/>
        <tr>
       <td>
           <xsl:value-of select="preceding-sibling::node()[position()=1]/Investment"/> - <xsl:value-of select="Investment"/>
       </td>
       </tr>
     </xsl:for-each>

0 - 49999
49999 - 99999
99999 - 249999
249999 - 499999
499999 - 999999
- 2000000
2000000 - 3000000
3000000 - 50000000
50000000 - 100000000
100000000+
 
Old June 9th, 2006, 05:32 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

For the straight sort, you just want

<xsl:for-each select="DealerCommission/Investment">
 <xsl:sort select="." data-type="number"/>
 <v><xsl:value-of select="."/></v>
</xsl:for-each>

To get ranges, do a second pass on the result of the first pass. To do this in XSLT 1.0, embed the for-each inside an xsl:variable, then use the xx:node-set extension to process the contents of the variable.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 12th, 2006, 01:54 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your quick responses. Finally i'd made changes to raw xml (generating xml with seq order 0,1,2,3,4 etc.. instead of 5,6,7,0,1,2,3..). i didn't change anything in xsl code. It works great.

$0 - $49,999.00 4.000
$49,999.00 - $99,999.00 3.000
$99,999.00 - $249,999.00 2.250
$249,999.00 - $499,999.00 1.250
$499,999.00 - $999,999.00 0.800
$999,999.00 - $2,000,000.00 0.800
$2,000,000.00 - $3,000,000.00 0.640
$3,000,000.00 - $50,000,000.00 0.400
$50,000,000.00 - $100,000,000.00 0.200
$100,000,000.00+ 0.120

I appreciate your great help.
Thanks
Ram






Similar Threads
Thread Thread Starter Forum Replies Last Post
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
preceding-sibling descendant xaun XSLT 3 February 28th, 2006 02:48 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
preceding-sibling after sort rushman XSLT 3 January 18th, 2005 11:08 AM
preceding-sibling behaviour andrewcday XSLT 6 December 3rd, 2004 03:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.