<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Expressing IT &#187; XML Attributes</title>
	<atom:link href="http://developer.expressionz.in/blogs/tag/xml-attributes/feed/" rel="self" type="application/rss+xml" />
	<link>http://developer.expressionz.in/blogs</link>
	<description>User Interface : just another, but a serious developers weblog</description>
	<lastBuildDate>Thu, 20 May 2010 18:05:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working with XML Node Attributes in XSLT</title>
		<link>http://developer.expressionz.in/blogs/2008/04/04/working-with-xml-node-attributes-in-xslt/</link>
		<comments>http://developer.expressionz.in/blogs/2008/04/04/working-with-xml-node-attributes-in-xslt/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 08:17:25 +0000</pubDate>
		<dc:creator>Nikhil</dc:creator>
				<category><![CDATA[XSL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML Attributes]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://developer.expressionz.in/blogs/?p=15</guid>
		<description><![CDATA[If you use XML and XSL, then you might have come across a time , when you have to play around with attributes and values of XML nodes in you XSL. They are loads of sites with long winded info about this, but none I found were brief and precise ... This is NO XML/XSL TUTORIAL,but my attempt to put-together some sort of cheat list ...
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F04%2F04%2Fworking-with-xml-node-attributes-in-xslt%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeveloper.expressionz.in%2Fblogs%2F2008%2F04%2F04%2Fworking-with-xml-node-attributes-in-xslt%2F&amp;source=nikhild&amp;style=normal&amp;hashtags=Tutorials,XML,XML+Attributes,XSL,XSLT" height="61" width="50" /><br />
			</a>
		</div>
<p>If you use XML and XSL, then you might have come across a time , when you have to play around with attributes and values of XML nodes in you XSL. They are loads of sites with long winded info about this, but none I found were brief and precise &#8230; This is NO XML/XSL TUTORIAL,but my attempt to put-together some sort of cheat list &#8230;</p>
<p>The sample XML that we will working with looks like this&#8230;</p>
<blockquote><p><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;<br />
&lt;?xml-stylesheet type="text/xsl" href="food.xsl"?&gt;<br />
&lt;food&gt;<br />
&lt;fruits type="tropical"&gt;<br />
&lt;item name="mango" moreinfo="http://www.mango.com"&gt;Mango is the king of fruits&lt;/item&gt;<br />
&lt;item name="banana" moreinfo="http://www.banana.com"&gt;Banana once a day , keeps the doctor away&lt;/item&gt;<br />
&lt;item name="orange" moreinfo="http://www.orange.com"&gt;Orange is the color and rich in vitamin C&lt;/item&gt;<br />
&lt;item name="Papaya" moreinfo="http://www.papaya.com"&gt;Papaya - Hot when raw, cold when ripe&lt;/item&gt;<br />
&lt;/fruits&gt;<br />
&lt;/food&gt;</code></p></blockquote>
<p>So Lets begin transforming our above XML using XSL</p>
<p><strong>Example 1 : Displaying value at a chosen Attribute</strong></p>
<blockquote><p><code>&lt;xsl:value-of select="/food/fruits/item[@name='orange']" /&gt;&lt;br /&gt;<br />
to get more information about &lt;a href="{/food/fruits/item[@name='orange']/@moreinfo}" target="new" &gt;&lt;xsl:value-of select="/food/fruits/item[@name='orange']/@name" /&gt; &lt;/a&gt;</code></p></blockquote>
<p>HTML result will look like</p>
<blockquote><p><code>Orange is the color and rich in vitamin C,<br />
to get more information about &lt;a href="http://www.orange.com" target="new"&gt;</code></p></blockquote>
<hr/>
<p><strong>Example 2 : Looping through and displaying all XML Attribute Names and their Values</strong></p>
<blockquote><p> <code>&lt;xsl:for-each select="/food/fruits/item/@*"&gt;<br />
  attribute name : &lt;xsl:value-of select="name()"/&gt;,&#160;<br />
    attribute value : &lt;xsl:value-of select="."/&gt;&#160; &lt;br /&gt;<br />
  &lt;/xsl:for-each&gt;</code></p></blockquote>
<p>HTML result will look like</p>
<blockquote><p><code><br />
attribute name : name,  attribute value : mango<br />
attribute name : moreinfo,  attribute value : http://www.mango.com<br />
attribute name : name,  attribute value : banana<br />
attribute name : moreinfo,  attribute value : http://www.banana.com<br />
attribute name : name,  attribute value : orange<br />
attribute name : moreinfo, attribute value : http://www.orange.com<br />
attribute name : name,  attribute value : Papaya<br />
attribute name : moreinfo,  attribute value : http://www.papaya.com<br />
</code></p></blockquote>
<hr/>
<strong><a title="download" href="http://developer.expressionz.in/blogs/wp-content/plugins/download-monitor/download.php?id=4" target="_blank">Download all the above files here (111 downloads)</a></strong></p>
<p><br/><br />
Watch this space, I&#8217;ll keep updating this with new findings&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.expressionz.in/blogs/2008/04/04/working-with-xml-node-attributes-in-xslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
