Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extracting tag names from xml

Status
Not open for further replies.

YYYYUU

Programmer
Dec 13, 2002
47
GB
Is there any easy way using xsl to extract the xml tag names from an xml document. This is so I can use the xml tag names as headers fields in a merge document.
 
This looks like something I might like to use eventually, so, as you have not had any replies yet, I have done a little research and come up with this:

We should be able to use the XPath local-name() function. Here is the Microsoft Example...
==============================
XSLT File (sample.xsl)
Code:
<xsl:stylesheet xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL] version=&quot;1.0&quot;>
   <xsl:output method=&quot;html&quot;/>
  <xsl:template match=&quot;/&quot;>
      <html>
         <body>
            <h3>local-name() Function</h3>
            
            <xsl:apply-templates />
                     
         </body>
      </html>
  </xsl:template>
  
  <xsl:template match=&quot;*&quot;>
      <xsl:value-of select=&quot;local-name()&quot;/> = <xsl:value-of select=&quot;text()&quot;/><br/>
      <xsl:apply-templates select=&quot;*&quot;/>
  </xsl:template>
</xsl:stylesheet>
=========================
Running this against an xml file gives a series of lines...
tag = tag-value

Of course this returns all the tags so we need to filter out the duplicates. I can't see an elegant way of doing this so would be pleased if anyone could suggest. [I am think along the lines of stuffing the tag into a variable if it is not present].
 
Hi,

How to you run this xsl file against the xml file?

Thanks,
scripter73


Change Your Thinking, Change Your Life.
 
>> How to you run this xsl file against the xml file?

If your on a Windows platform you can use the msxsl.exe app that is free for download from msdn.microsoft.com (i think that's where i got it [lol]). Of course it is dependent on a MSXML(n).DLL being installed i think.

Otherwise you can get XML/XSL processors from apache.org that are similar to use.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top