Re: [xsl] flat xml tree to indent one

Subject: Re: [xsl] flat xml tree to indent one
From: Matthieu Ricaud-Dussarget <matthieu.ricaud@xxxxxxxxx>
Date: Tue, 21 Dec 2010 15:28:54 +0100
Thank you Michael and David,
This List is incredibly reactive, thanks to guys like you, that's really appreciated.

Just for information, i'm working on tranformation of inDesign IDML format to some more easy XML... and then convert it to XHTML or epub for example.
An interresting challenge ;)

I understood both of your solutions, and i will adapt the a mixe of them to my real case.
I agree Mickael, this is not a real grouping case, my apologize.

I could'nt find a way to iterate through attribute, cause following:@*[1] is not valid xpath syntax !
But using position() or removing attribute reccursivly make the trick !
I'm glad, I learn 2 xpath2 functions today : exist() and remove() !

One more time thanks a lot to you too,


Le 21/12/2010 13:47, Michael Kay a icrit :
On 21/12/2010 12:30, Matthieu Ricaud-Dussarget wrote:
Hi all,

This is a grouping question one more time.
It's not actually a grouping problem as commonly understood.

For such an input :

<p foo="foo_att" bar="bar_att" foobar="foobar_att">my text</p>

I'd like such an output :

<foo><bar><foobar>my text</foobar></bar></foo>

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)

You need to process the attributes one at a time, recursively:

<xsl:template match="p[@*]">
<xsl:variable name="temp">
<xsl:copy-of select="remove(@*, 1)"/>
<xsl:element name="{name(@*[1])}">
<xsl:copy-of select="child::node()"/>
<xsl:apply-templates select="$temp"/>

<xsl:template match="p[not(@*)]">
<xsl:sequence select="."/>

Michael Kay

Matthieu Ricaud
Service Livre numirique

Current Thread