[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Merging common XML tree

Subject: Re: Merging common XML tree
From: Mathieu Malaterre <mathieu.malaterre@xxxxxxxxx>
Date: Thu, 8 Jul 2010 12:49:35 +0200
Re:  Merging common XML tree
On Thu, Jul 8, 2010 at 12:02 PM, Florent Georges <lists@xxxxxxxxxxxx> wrote:
> Mathieu Malaterre wrote:
>
>  Hi,
>
>> <dirs>
>>   <dir name="A">
>>     <dir name="B">
>>       <file name="C">
>>     </dir>
>>   </dir>
>>   <dir name="A">
>>     <dir name="B">
>>       <file name="D">
>>     </dir>
>>   </dir>
>> </dirs>
>
>> and my target output tree should looks like:
>
>> <dirs>
>>   <dir name="A">
>>     <dir name="B">
>>       <file name="C">
>>       <file name="D">
>>     </dir>
>>   </dir>
>> </dirs>
>
>  I would use recursive grouping:
>
>    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>                    xmlns:my="..."
>                    exclude-result-prefixes="#all"
>                    version="2.0">
>
>       <xsl:output indent="yes"/>
>
>       <xsl:template match="dirs">
>          <xsl:copy>
>             <xsl:call-template name="my:handle-dirs">
>                <xsl:with-param name="dirs" select="*"/>
>             </xsl:call-template>
>          </xsl:copy>
>       </xsl:template>
>
>       <xsl:template name="my:handle-dirs">
>          <xsl:param name="dirs" as="element(dir)+"/>
>          <xsl:for-each-group select="$dirs" group-by="@name">
>             <dir name="{ current-grouping-key() }">
>                <xsl:copy-of select="current-group()/file"/>
>                <xsl:if test="current-group()/dir">
>                   <xsl:call-template name="my:handle-dirs">
>                      <xsl:with-param name="dirs" select="
>                         current-group()/dir"/>
>                   </xsl:call-template>
>                </xsl:if>
>             </dir>
>          </xsl:for-each-group>
>       </xsl:template>
>
>    </xsl:stylesheet>
>
>  You may have to adapt the content of the for-each-group for the
> precise ordering you want between files and dirs when a dir
> contains both.

I have a limited set of filepath. For instance I cannot have
subdirectory if a file is present in a directory...

So I believe your script will work just fine for me ! Thanks a lot !
This saved me quite some time, in this yak-shaving task of utilizing
cmake to generate targetset structure for docbook olinking ...

Thanks again everyone,
--
Mathieu

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.