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

attributes

Status
Not open for further replies.

amiw

Programmer
Apr 1, 2003
113
GB
<Listing ranking=&quot;1&quot; title=&quot;Find it at CD Store&quot; description=&quot;The CD Store is a UK mail order company selling CDs.&quot; siteHost=&quot; biddedListing=&quot;true&quot;>

</Listing>

how do i get the text from the node when it is an attribute rather than the text within the node?

thanks
Michael
 
Hi,

Here's an example on how to print xml attributes using xsl:

<?xml version='1.0'?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;
<xsl:template match=&quot;/&quot;>

<HTML>
<BODY>

<p> Attributes found in the listing element: </p>

<p>

<xsl:for-each select=&quot;top/listing&quot;>

<xsl:value-of select=&quot;@ranking&quot;/> <br />

<xsl:value-of select=&quot;@title&quot;/> <br />

<xsl:value-of select=&quot;@description&quot;/> <br />

<xsl:value-of select=&quot;@siteHost&quot;/> <br />

<xsl:value-of select=&quot;@biddedListing&quot;/> <br />


</xsl:for-each>

</p>

</BODY>
</HTML>

</xsl:template>
</xsl:stylesheet>

I changed your xml, because it didn't contain a top or root element and I changed Listing to listing. For me it is much easier to work with all lower case to avoid confusion. (xml is case sensitive)

<?xml version=&quot;1.0&quot;?>

<!--How to list attributes in output
based on attributes in the input.
-->

<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;listing.xsl&quot;?>
<top>

<listing
ranking=&quot;1&quot;
title=&quot;Find it at CD Store&quot;
description=&quot;The CD Store is a UK mail order company selling CDs.&quot;
siteHost=&quot;biddedListing=&quot;true&quot;>
</listing>

</top>

You may want to create html attributes from the xml attributes. This is possible using the <xsl:attribute> element.

eg.
<!--first look for element -->
<xsl:for-each select=&quot;top/listing&quot;>
<!-- create an attribute title (tooltip in html) from xml attribute title -->
<xsl:attribute name=&quot;title&quot;>The title is
<xsl:value-of select=&quot;@title&quot;/></xsl:attribute>

HTH,

Lillu


If you want to get a job done, ask a busy person. (Sherry Conway Appel - American writer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top