[xsl] converting attributes to nested tags recursively

Subject: [xsl] converting attributes to nested tags recursively
From: Edward.Middleton@xxxxxxxxxxx
Date: Thu, 7 Feb 2002 14:51:08 +0900
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