Gautam
Gautam

Reputation: 1740

Getting the name of Node in xslt

I have a xml drafted as follows

<node1>
  <node2>
    <node3>
      val3
    </node3>
    <node4>
      val4
    </node4>
  </node2>
</node1>

i m using XSLT to get values from node3 and node 4 So far so good and I m getting the values. as

val3
val4

I m using the xslt loop as follows

<xsl:for-each select="/node1/node2">

</xsl:for-each>

Now I need to get the names of nodes also. i.e. i need the following output

node3: val3
node4: val4

Upvotes: 0

Views: 131

Answers (1)

Istao
Istao

Reputation: 7585

for instance :

  <xsl:template match="/">
    <xsl:for-each select="node1/node2/*">
      <xsl:value-of select="name()"/> : <xsl:value-of select="text()"/>
    </xsl:for-each>  
  </xsl:template>

I get :

node3 : 
      val3
    node4 : 
      val4

Upvotes: 1

Related Questions