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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding out the name of first node? probably dumb question

Status
Not open for further replies.

PennyH

Programmer
Oct 6, 2004
6
US
I am using XSL to display one of many XML files to users... in Internet Explorer. Everything is identical in the structure of the each of the XML files except the first/root node. First example:

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="test.xsl"?>
<Signature>
<item>
<line>Penny H</line>
<line>111 Any Street</line>
<line>Anytown, AnyState</line>
<line>Phone: 555-1111</line>
<line>Email: someone@somewhere.com</line>
</item>
<item>
<line>Adam H</line>
<line>111 Any Street</line>
<line>Anytown, AnyState</line>
<line>Phone: 555-1112</line>
<line>Email: someoneelse@somewhere.com</line>
</item>
</Signature>

second example:

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="test.xsl"?>
<Options>
<item>
<line>Ascending</line>
<line>Descending</line>
</item>
<item>
<line>Ordered By State</line>
<line>Ordered By City</line>
<line>Ordered By Last Name</line>
</item>
</Options>

I'd love to use the same XSL file for all the files, and I can get it to build the file exactly the way I want with one exception. Can I display the name of the root node?

Output I want:

Signature:

Penny H
111 Any Street
Anytown, AnyState
Phone: 555-1111
Email: someone@somewhere.com

Adam H
111 Any Street
Anytown, AnyState
Phone: 555-1112
Email: someoneelse@somewhere.com

AND:

Options:

Ascending
Descending

Ordered By State
Ordered By City
Ordered By Last Name


Like I said, I've got everything else displaying, but can't seem to figure out how to retrieve the name of the node i.e., <Signature> to return Signature and <Option> to return Option.

Thank you for any help!

 
Duh... figured it out...

First my reference at the top of my xsl was wrong...
Updating it to:

<xsl:stylesheet xmlns:xsl=" version="1.0">

Meant that name() function of xpath was available. Then I simply used

<xsl:value-of select="name(*)"/>

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top