jQuery in Action, 3rd edition
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Fetching TagName in XSL" Watch "Fetching TagName in XSL" New topic

Fetching TagName in XSL

Priya Jotwani
Ranch Hand

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


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

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"?>
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"
<xsl:template match="/">

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




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.

I agree. Here's the link: http://aspose.com/file-tools
subject: Fetching TagName in XSL
It's not a secret anymore!