Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Is there any way to show identical child nodes using xslt?

Question posted by: recalled1 (Newbie) on July 9th, 2008 12:33 AM
good day

i am really new to xml and i seem to be stuck. I have the following code:

<product-preference type="not">
<product ref="item1">Shadow Chrome</product>
<product ref="item2">Chrome</product>
</product-preference>

I need to display the "ref" and the description for both items in a browser. However i can't seem to figure it out. I tried an "xsl:for-each" but only the first item appeared. i then used :

<xsl:for-each select="product-preference[@type='not']/product">

to try narrowing the selection down. while this showed the items, i am unable to get the descriptions. Is there anyway to get the items and descriptions for both?? the output i am trying to acheive is:

item1-Shadow Chrome
item2-Chrome

please help. All assistance will be greatly appreciated

recalled1
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
roces's Avatar
roces
Newbie
7 Posts
July 10th, 2008
08:40 AM
#2

Re: Is there any way to show identical child nodes using xslt?
Check this transformation.

Code: ( text )
  1. <xsl:template match="/">
  2.     <xsl:for-each select="/product-preference[@type='not']/product">
  3.         <xsl:value-of select="concat(@ref, '-', text(), '&#xD;')"/>
  4.     </xsl:for-each>
  5. </xsl:template>

Reply
Reply
Not the answer you were looking for? Post your question . . .
180,785 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top XML Forum Contributors