How to creating a variable containing elements?
Posted: Wed Jan 28, 2009 11:50 pm
Greetings,
I am trying to create variables that contain elements rather than text values.
I have an XML file like this:
In my XSL sheet, I want to build 4 variables, one for each <item>. The variables might be something like this:
The problem is that items could be in any order, so I can't hard-code the Xpath. How can I assign each variable to its correct item, regardless of its position in the document?
I would be most grateful for a suggestion here..
Best wishes,
Karl Forsyth
I am trying to create variables that contain elements rather than text values.
I have an XML file like this:
Code: Select all
<document>
<item name='ItemRed'>
<text>item red text</text>
</item>
<item name='ItemYellow'>
<text>item yellow text</text>
</item>
<item name='ItemBlue'>
<text>item blue text</text>
</item>
<item name='ItemGreen'>
<text>item green text</text>
</item>
</document>
Code: Select all
<xsl:variable name="itemRed" select="document/item[1]"/>
<xsl:variable name="itemYellow" select="document/item[2]"/>
<xsl:variable name="itemBlue" select="document/item[3]"/>
<xsl:variable name="itemGreen" select="document/item[4]"/>
I would be most grateful for a suggestion here..
Best wishes,
Karl Forsyth