Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: grouping parallel xml nodes? [Thread Next] Re: grouping parallel xml nodes?To: NULL Date: 7/10/2006 1:14:00 PM
never mind. It was easy one.
just added <xsl:copy-of select="node()"/> to the mode="copy" template.
Thank you, Mr. M. Honner for you answer.
Raffy
"Raffy Gim" wrote:
> Dear Mr. Martin Honner,
>
> Your answer is greatful.
> May I ask one more question?
> How could you copy all subtree as they appears if <row> node has several
> children?
> I thought I can easily modify the answer using copy-of, but have not figured.
>
> input xml:
>
> <layout>
> <row type="1" name="one"><color>b1</color></row>
> <row type="9999" name="first spacer"/>
> <row type="2" name="two"><color>b2</color></row>
> <row type="3" name="three"><color>b3</color></row>
> <row type="7 name="seven"><color>b4</color></row>
> <row type="9999" name="second spacer"/>
> <row type="4" name="four"><color>b5</color></row>
> <row type="5" name="five"><color>b6</color></row>
> </layout>
>
> the output xml:
> <layout>
> <group name="nogroup">
> <row type="1" name="one"><color>b1</color></row>
> </group>
> <group name="first spacer">
> <row type="2" name="two"><color>b2</color></row>
> <row type="3" name="three"><color>b3</color></row>
> <row type="7 name="seven"><color>b4</color></row>
> </group>
> <group name="second spacer">
> <row type="4" name="four"><color>b5</color></row>
> <row type="5" name="five"><color>b6</color></row>
> </group>
> </layout>
>
> thx in advance again,
>
> Raffy
>
> "Martin Honnen" wrote:
>
> >
> >
> > Raffy Gim wrote:
> >
> >
> > > <layout>
> > > <row type="1" name="one"/>
> > > <row type="9999" name="first spacer"/>
> > > <row type="2" name="two"/>
> > > <row type="3" name="three"/>
> > > <row type="7 name="seven"/>
> > > <row type="9999" name="second spacer"/>
> > > <row type="4" name="four"/>
> > > <row type="5" name="five"/>
> > > </layout>
> > >
> > > The xml I want to have from the original xml above is
> > > <layout>
> > > <group name="nogroup">
> > > <row type="1" name="one"/>
> > > </group>
> > > <group name="first spacer">
> > > <row type="2" name="two"/>
> > > <row type="3" name="three"/>
> > > <row type="7 name="seven"/>
> > > </group>
> > > <group name="second spacer">
> > > <row type="4" name="four"/>
> > > <row type="5" name="five"/>
> > > </group>
> > > </layout>
> >
> > One way is to use
> >
> > <?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="layout">
> > <xsl:copy>
> > <xsl:apply-templates select="@*" />
> > <xsl:apply-templates select="row[1]" />
> > </xsl:copy>
> > </xsl:template>
> >
> > <xsl:template match="row[@type = '9999']">
> > <group name="{@name}">
> > <xsl:apply-templates select="following-sibling::row[1][@type !=
> > '9999']" mode="copy" />
> > </group>
> > <xsl:apply-templates select="following-sibling::row[@type =
> > '9999'][1]" />
> > </xsl:template>
> >
> > <xsl:template match="row">
> > <group name="nogroup">
> > <xsl:copy>
> > <xsl:apply-templates select="@* " />
> > </xsl:copy>
> > </group>
> > <xsl:apply-templates select="following-sibling::row[1]" />
> > </xsl:template>
> >
> > <xsl:template match="row" mode="copy">
> > <xsl:copy>
> > <xsl:apply-templates select="@*" />
> > </xsl:copy>
> > <xsl:apply-templates select="following-sibling::row[1][@type !=
> > '9999']" mode="copy" />
> > </xsl:template>
> >
> > <xsl:template match="@*">
> > <xsl:copy />
> > </xsl:template>
> >
> > </xsl:stylesheet>
> >
> >
> > --
> >
> > Martin Honnen --- MVP XML
> > http://JavaScript.FAQTs.com/
> >
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
