[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

converting attributes to nested tags recursively

Subject: converting attributes to nested tags recursively
From: Edward.Middleton@xxxxxxxxxxx
Date: Thu, 7 Feb 2002 14:51:08 +0900
naming attributes in fds
Hi,

I have a file like the following
<tagA attribreq="attribreqvalue1" attrib1="fds" attrib2="hdg">
	<TagB>Text1</TabB>
	<tagA attribreq="attribreqvalue1" attrib1="fds" attrib2="hdg">
</tagA>

And I am trying to convert it to the following
<attribreq attrib="attribreqvalue1">
	<tag name="attrib1" value="fds">
		<tag name="attrib2" value="hdg">
			<tagB>Text1</tagB>
		</tag>
	</tag>
</attribreq>
<attribreq attrib="attribreqvalue1">
	<tag name="attrib1" value="fds">
		<tag name="attrib2" value="hdg"/>
	</tag>
</attribreq>

I would like to do it recursively something like the following. So that I can optionally add specific matches for processing
specific tags.
<xsl:template match="@*">
	<tag>
		<xsl:attribute nam="name"><xsl:value-of select="name()"/></xsl:attribute>
		<xsl:attribute nam="value"><xsl:value-of select="current()"/></xsl:attribute>
		<xsl:template select="parent::*/(@*|tagB)"/>
	</tag>
</xsl:template>
<xsl:template match="tagB">
	<xsl:copy-of select="."/>
</xsl:template>

The number of attributes will vary.

Thanks in advance

Edward

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.