Nice! that is exactly I need, you are the man!
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:Octhb2GRGHA.424@TK2MSFTNGP12.phx.gbl...[color=blue]
>
>
> davidw wrote:
>[color=green]
> > I have flat xml like this
> >
> > <field name="a1"/>
> > <field name="a2" merge="true"/>
> > <field name="a3"/>
> > <field name="a4"/>
> > <field name="a5" merge="true"/>
> > <field name="a6" merge="true"/>
> > <field name="a7"/>
> >
> > but I want to loop through them like this
> > <field name="a1">
> > <field name="a2" merge="true"/>
> > </field>
> > <field name="a3"/>
> > <field name="a4">
> > <field name="a5" merge="true"/>
> > <field name="a6" merge="true"/>
> > </field>
> > <field name="a7"/>
> >
> > It means nodes with merge attribute is child of the previous node. I[/color][/color]
only[color=blue][color=green]
> > need handle one level for now, any suggestion?[/color]
>
> You could apply an XSLT transformation to have the nested structure:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:output method="xml" indent="yes" />
>
> <xsl:template match="fields">
> <xsl:copy>
> <xsl:apply-templates select="@*" />
> <xsl:apply-templates select="field[not(@merge)]" />
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="field">
> <xsl:copy>
> <xsl:apply-templates select="@*" />
> <xsl:apply-templates
> select="following-sibling::field[1][@merge = 'true']" mode="child" />
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="field" mode="child">
> <xsl:copy>
> <xsl:apply-templates select="@* | node()" />
> </xsl:copy>
> <xsl:apply-templates
> select="following-sibling::field[1][@merge = 'true']" mode="child" />
> </xsl:template>
>
> <xsl:template match="@*">
> <xsl:copy />
> </xsl:template>
>
> </xsl:stylesheet>
>
> --
>
> Martin Honnen --- MVP XML
>
http://JavaScript.FAQTs.com/[/color]