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 5th, 2007, 10:08 AM
Tre Tre is offline
Authorized User
 
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem accessing the following siblings.

Hi,

Here is my XML:

- <Portfolio>
- <Data>
  <SecurityTypeID>1</SecurityTypeID>
  <CodeOrder>5</CodeOrder>
  <SecurityTypeName>Equity</SecurityTypeName>
  <Current_x003C_br_x003E_Value>119,278.89</Current_x003C_br_x003E_Value>
  <Unrealized_x003C_br_x003E_Gain_x002F_Loss>50,783. 29</Unrealized_x003C_br_x003E_Gain_x002F_Loss>
  </Data>
- <Data>
  <SecurityTypeID>2</SecurityTypeID>
  <CodeOrder>15</CodeOrder>
  <SecurityTypeName>Fixed Income</SecurityTypeName>
  <Current_x003C_br_x003E_Value>14,475.00</Current_x003C_br_x003E_Value>
  <Unrealized_x003C_br_x003E_Gain_x002F_Loss>2,677.6 5</Unrealized_x003C_br_x003E_Gain_x002F_Loss>
  </Data>
- <Data>
  <SecurityTypeID>14</SecurityTypeID>
  <CodeOrder>25</CodeOrder>
  <SecurityTypeName>International</SecurityTypeName>
  <Current_x003C_br_x003E_Value>53,851.90</Current_x003C_br_x003E_Value>
  <Unrealized_x003C_br_x003E_Gain_x002F_Loss>7,586.1 1</Unrealized_x003C_br_x003E_Gain_x002F_Loss>
  </Data>
- <Data>
  <SecurityTypeID>22</SecurityTypeID>
  <CodeOrder>30</CodeOrder>
  <SecurityTypeName>Real Estate</SecurityTypeName>
  <Current_x003C_br_x003E_Value>21,894.00</Current_x003C_br_x003E_Value>
  <Unrealized_x003C_br_x003E_Gain_x002F_Loss>7,468.6 8</Unrealized_x003C_br_x003E_Gain_x002F_Loss>
  </Data>
- <Data>
  <SecurityTypeID>3</SecurityTypeID>
  <CodeOrder>50</CodeOrder>
  <SecurityTypeName>Cash and Money Market</SecurityTypeName>
  <Current_x003C_br_x003E_Value>2,329.39</Current_x003C_br_x003E_Value>
  </Data>
- <Data>
  <SecurityTypeID>255</SecurityTypeID>
  <CodeOrder>255</CodeOrder>
  <SecurityTypeName>Totals</SecurityTypeName>
  <Current_x003C_br_x003E_Value>211,829.20</Current_x003C_br_x003E_Value>
  <Unrealized_x003C_br_x003E_Gain_x002F_Loss>68,515. 75</Unrealized_x003C_br_x003E_Gain_x002F_Loss>
  </Data>
  </Portfolio>

I want to be able to display those five node vales horizontally across a page within a table.

I can access the first node no problem by simply doing:

<xsl:value-of select=".//Current_x003C_br_x003E_Value" />

I can then populate the second column by doing:

<xsl:value-of select="following::*[1]/Current_x003C_br_x003E_Value" />

So far so good! But now I have a problem, I can't access any of the other following nodes.

How do I get the 3rd, 4th, and 5th nodes??

Any advice, comments or help on this matter would be most helpful and appreciated.

Regards,

Trevor.


 
Old June 5th, 2007, 10:16 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The way you get to the 3rd, 4th, and 5th nodes depends very greatly on where you are starting from, which you don't actually say. Your problem is almost certainly one of establishing the right initial context.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 5th, 2007, 10:25 AM
Tre Tre is offline
Authorized User
 
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am starting from the beginning of the node set that I have provided above. Other, <Portfolio> node sets may follow however this example contains one <Portfolio> with five child elements within that <Portfolio>

 
Old June 5th, 2007, 10:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I have no idea what you mean by "the beginning of the node set". You have shown an XML document: you could be referring to the document node, to the outermost element node, to the first Data element, or pretty well anything else. You need to be much more precise than this.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 5th, 2007, 10:52 AM
Tre Tre is offline
Authorized User
 
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using a for-each loop to loop through all of the "Portfolio" nodes starting at the beginning of the XML document I have shown. The XML document I have shown currently only has one "Portfolio" node.

While I am visiting each "Portfolio" node I want to process all its child elements, specifically "Current_x003C_br_x003E_Value".

It is these child nodes that I want to put across the top of the page before moving on to the next Portfolio node.

 
Old June 5th, 2007, 11:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If the context node is a Portfolio element, then Current_x003C_br_x003E_Value is not a child, it is a grandchild. You can address the different instances of Current_x003C_br_x003E_Value as Data[1]/Current_x003C_br_x003E_Value, Data[2]/Current_x003C_br_x003E_Value, Data[3]/Current_x003C_br_x003E_Value and so on. You don't need the following or following-sibling axis.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 5th, 2007, 11:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Incidentally, if your context node is a Portfolio element, then <xsl:value-of select="following::*[1]/Current_x003C_br_x003E_Value" /> should not select anything in the data you have shown. The following axis never selects descendants of the context node.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Introducing parent node to specific siblings Frimann XSLT 11 July 3rd, 2008 03:20 PM
first element in array nesting siblings rjonk XSLT 1 May 18th, 2008 03:53 PM
Comparing siblings Chamkaur XSLT 1 June 17th, 2006 09:56 PM
Turning Siblings into Children wolfie78uk XSLT 3 December 22nd, 2005 08:33 AM
Accessing Attributes of Siblings AForgue XSLT 2 November 4th, 2003 01:39 PM





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