This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Fetching TagName in XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Fetching TagName in XSL" Watch "Fetching TagName in XSL" New topic
Author

Fetching TagName in XSL

Priya Jotwani
Ranch Hand

Joined: Oct 30, 2002
Posts: 53
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

Joined: Sep 10, 2004
Posts: 53
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fetching TagName in XSL