This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
converting attributes to nested tags recursively
- From: Edward dot Middleton at nikonoa dot net
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 7 Feb 2002 14:51:08 +0900
- Subject: [xsl] converting attributes to nested tags recursively
- Reply-to: xsl-list at lists dot mulberrytech dot com
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