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

Re: This could be simple, but not for me!

Subject: Re: This could be simple, but not for me!
From: Ramkumar Menon <ram.menon@xxxxxxxxxx>
Date: Wed, 26 May 2004 16:42:57 +0530
ramkumar menon
A simple solution using groups.

- Menon

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="Root">
<xsl:for-each-group select="Community/A/B/Info/Detail" group-by="concat(@no,',',.)">
<xsl:text>&#x0A;</xsl:text>
<xsl:value-of select="current-grouping-key()"/>
<xsl:text>&#x0A;</xsl:text>
<xsl:for-each-group select="current-group()" group-by="parent::Info/parent::B/parent::A/parent::Community/City">
<xsl:value-of select="current-grouping-key()"/>
<xsl:text>&#x0A;</xsl:text>
<xsl:for-each-group select="current-group()" group-by="parent::Info/parent::B//Name">
<xsl:value-of select="current-grouping-key()"/>
<xsl:text>&#x0A;</xsl:text>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>



Andreas L. Delmelle wrote:


-----Original Message-----
From: Kenny Bogoe (BogoeMD) [mailto:kenny@xxxxxxxxx]




Hi,




Though I have been working sometime with XSLT, I am having
trouble with this transformation.
Anyone know how to do this?
The XML source is from a database and is really really huge
in size, so performance of the transformation is very critical...




Not sure whether it can be optimized further, but it seems to yield the desired output...

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" indent="yes" encoding="ISO-8859-1" />

<!-- this key will return all cities having a Detail
    descendant with the supplied value for @no -->
<xsl:key name="city-by-detail" match="City"
        use="following-sibling::A/B/Info/Detail/@no" />

<xsl:key name="detail-key" match="Detail"
        use="@no" />

<xsl:variable name="unique-details"
             select="//Detail[generate-id()=generate-id(
               key('detail-key',@no))]" />

<xsl:template match="/">
 <xsl:apply-templates select="$unique-details" />
</xsl:template>

<xsl:template match="Detail">
 <xsl:value-of select="concat('&#x0A;',@no,', ',.,'&#x0A;')" />
 <xsl:apply-templates select="key('city-by-detail',@no)">
   <xsl:with-param name="pNo" select="@no" />
 </xsl:apply-templates>
</xsl:template>

<xsl:template match="City">
 <xsl:param name="pNo" />
 <xsl:apply-templates select="following-sibling::A/B/Name[
                        following::Info[1]/Detail/@no=$pNo]" />
</xsl:template>

<xsl:template match="Name">
 <xsl:if test="position()=1">
   <xsl:value-of select="concat('&#x0A;&#x09;',
                   ancestor::Community/City)" />
 </xsl:if>
 <xsl:value-of select="concat('&#x0A;&#x09;&#x09;',.)" />
</xsl:template>

</xsl:stylesheet>


Hope this helps!



Greetz,


Andreas

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.