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

RE: RE: RE: merging generic elements in a parent-child

Subject: RE: RE: RE: merging generic elements in a parent-child
From: "Matias Woloski" <woloski@xxxxxxxx>
Date: Fri, 28 Jun 2002 13:41:36 -0300
xsl parent child
I finally solved this... if anyone want to see the solution here it is.
Thanks to all for the help!

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="TopElement" select="'Persona'"/>

<xsl:output method="xml" indent="yes"/>
<!-- key into the parent attributes -->
<!-- where the keyed value is a combination of the parent -->
<!-- key type and the value of that parent key id -->
<xsl:key name="kIDs" match="root/*/@*[substring(name(),1,2) = 'id']"
use="concat(substring(name(),3),'=',.)"/>
<!-- key for grouping like parented and named -->
<xsl:key name="kIDName" match="root/*/@*[substring(name(),1,2) = 'id']"
use="concat(name(..),'|',substring(name(),3),'=',.)"/>

<xsl:template match="/">
  <root>
    <!-- select only top-level elements that have no parented element for
id????? attribute -->
  <xsl:element name="{$TopElement}Group">
     <xsl:apply-templates select="root/*[name() = $TopElement]"
mode="top-levels"/>
    </xsl:element>
  </root>
</xsl:template>

<xsl:template match="*" mode="top-levels">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates
select="key('kIDs',concat(name(),'=',@id))[generate-id() =
generate-id(key('kIDName',concat(name(..),'|',substring(name(),3),'=',.)))]/
.."
mode="group-start">
     <xsl:with-param name="parent-name" select="name()"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="*" mode="group-start">
 <xsl:param name="parent-name"/>
 <xsl:variable name="parent-id" select="@*[substring(name(),3) =
$parent-name]"/>
 <!-- begin this child group -->
 <xsl:element name="{name()}Group">
  <!-- show all elements parented by the same id and with the same name -->
    <xsl:apply-templates
select="key('kIDName',concat(name(),'|',$parent-name,'=',$parent-id))/.."/>
 </xsl:element>
</xsl:template>

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <!-- apply templates to those elements parented by this id (grouped by
name) -->
    <xsl:apply-templates
select="key('kIDs',concat(name(),'=',@id))[generate-id() =
generate-id(key('kIDName',concat(name(..),'|',substring(name(),3),'=',.)))]/
.."
mode="group-start">
     <xsl:with-param name="parent-name" select="name()"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>
</xsl:stylesheet>

regards,
Matias



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.