Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XSL Transform - XML with nested same names

$
0
0

Hi All,

I'm having a problem with transforming some XML with nested same names.
Sample XML is:

<Objects><Object><Property><Property Name="prop1">abcd</Property><Property Name="prop2">1234</Property>
    ..more stuff ..</Property><Property><Property Name="prop1">vxyz</Property><Property Name="prop2">5678</Property>
    ..more stuff ..</Property><Property><Property Name="prop1">opqr</Property><Property Name="prop2">9012</Property>
    ..more stuff ..</Property></Object></Objects>

What I want to return is:

<Items>
  <Item>
    <prop1>abcd</prop1>
    <prop2> 1234</prop2>
    ..
  </Item>
  <Item> ... </Item>
  etc.
</Items>

The XSL I have so far is:

<xsl:template match="/"><xsl:element name="Items"><xsl:for-each select="Objects/Object/Property"><xsl:element name="Item"><xsl:element name="prop1"><xsl:value-of select="//Property[@Name = 'prop1']" /></xsl:element><xsl:element name="prop2"><xsl:value-of select="//Property[@Name = 'prop2']" />
          .. more stuff ..</xsl:element></xsl:element></xsl:for-each></xsl:element></xsl:template>

This returns the correct number of "Item" nodes (in this case 3), but all data in all "Item" nodes is the same - taken from the first Objects/Object/Property node.

Can someone point me in the right direction here?
Thx in advance!!
M.



Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>