• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fetching TagName in XSL

 
Priya Jotwani
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an XML file which has some Tags and its values.Can somebody tell me as to how can I find TagName and its corresponding values ?
Suppose , i have an entry like this :

<Name>Priya</Name>
<Country>India</Country>

How can i fetch Tag 'Name' and its value 'Priya' using XSL.

TIA,
Priya
 
Rahesh Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya Jotwani
restructure your xml as the one below

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Test.xsl"?>
<Root>
<Name>Priya</Name>
<Country>India</Country>
</Root>
and save it as Test.xml

have your xsl as the one below
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>

<body>
<xsl:for-each select="Root">
<xsl:value-of select="Name"/>
</xsl:for-each>
</body>

</html>

</xsl:template>

</xsl:stylesheet>

save it as Test.xsl.

The href in ur xml file is the way by which u map ur xml to xsl,and the template match in ur xsl in going to the root node,actually u cannot retrieve any dat without having a root node in ur xml,so have a root node as named as Root in the xml file.so the syntax to select the attribute is value-of select.This is the way to retrieve the data from ur chile tag,i dont think we can retrieve the tag name.

Thanks
Rahesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic