[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] This could be simple, but not for me!


Subject: RE: [xsl] This could be simple, but not for me!
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Tue, 25 May 2004 21:17:33 +0200

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