 |
| 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
|
|
|
|

June 5th, 2007, 10:08 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 5th, 2007, 10:16 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

June 5th, 2007, 10:25 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

June 5th, 2007, 10:40 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

June 5th, 2007, 10:52 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 5th, 2007, 11:03 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

June 5th, 2007, 11:13 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|
 |