|
Subject: Re: [xsl] flat xml tree to indent one From: Michael Kay <mike@xxxxxxxxxxxx> Date: Tue, 21 Dec 2010 12:47:25 +0000 |
Hi all,It's not actually a grouping problem as commonly understood.
This is a grouping question one more time.
You need to process the attributes one at a time, recursively:
For such an input :
<p foo="foo_att" bar="bar_att" foobar="foobar_att">my text</p>
I'd like such an output :
<p> <foo><bar><foobar>my text</foobar></bar></foo> </p>
the order foo/bar/foobar isn't important here. <foobar><bar><foo>my text</foo></bar></foobar> would also be ok.
This should work for any number of attributes (including none)
<xsl:template match="p[@*]">
<xsl:variable name="temp">
<p>
<xsl:copy-of select="remove(@*, 1)"/>
<xsl:element name="{name(@*[1])}">
<xsl:copy-of select="child::node()"/>
</xsl:element>
</p>
</xsl:variable>
<xsl:apply-templates select="$temp"/>
</xsl:template><xsl:template match="p[not(@*)]"> <xsl:sequence select="."/> </xsl:template>
Michael Kay Saxonica
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] flat xml tree to indent o, David Carlisle | Thread | Re: [xsl] flat xml tree to indent o, Matthieu Ricaud-Duss |
| Re: [xsl] flat xml tree to indent o, David Carlisle | Date | Re: [xsl] Novice Question - matchin, Hermann Stamm-Wilbra |
| Month |