Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: grouping parallel xml nodes?

From: RaffyGim@-----------.---------.---
To: NULL
Date: 7/10/2006 12:40:00 PM

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/
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent