C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » XML »

XSLT Tranformation - Node to attributes


Posted Date: 19 Sep 2009    Resource Type: Code Snippets    Category: XML
Author: ABitSmartMember Level: Diamond    
Rating: 1 out of 5Points: 10



XSLT Tranformation



The following is code snippet demonstrates an XSLT transformation of a node to an attribute.

This is the sample XML File,

<Head>
<Child>
<Grandchild1>Test1</Grandchild1>
<Grandchild2>Test2</Grandchild2>
<Grandchild3>Test3</Grandchild3>
</Child>
</Head>


The final output expected is,

<Head>
<Child Grandchild1="Test1" Grandchild2="Test2" Grandchild3="Test3">
</Child>
</Head>

Note: The grandchild nodes are converted into attributes.

Here is the XSLT for the same,

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Head">
<Head>
<xsl:apply-templates/>
</Head>
</xsl:template>

<xsl:template match="Child">
<Child>
<xsl:for-each select="*">
<xsl:attribute name="{name()}">
<xsl:value-of select="text()"/>
</xsl:attribute>
</xsl:for-each>
</Child>
</xsl:template>
</xsl:stylesheet>


Have fun

For more details, visit http://abitsmart.com/?p=210



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
XSLT Node to Attribute  .  XSLT Element to Attribute  .  XSLT  .  XML Node to Attribute  .  XML Element to Attribute  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Connecting XML With DropDownlist in asp.net Through Coding
Previous Resource: Add Birth Day Details in XML File
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use