Re: [xsl] Converting a SQL XML Resultset using XSL...

Subject: Re: [xsl] Converting a SQL XML Resultset using XSL...
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Thu, 28 Feb 2002 20:53:09 +0100
Hello Aaron,

if you don't want the SQL-solution or can not use it, here is the
XSLT-solution:

Your problem is a grouping problem. Some information you can find here:
http://www.jenitennison.com/xslt/grouping/index.xml. In your case you need a
multiple level grouping, first by id, second by tag_name. Using the
Muenchian Method you need for this at first the id and at second a
concatenated string with id and tag_name:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>

<xsl:key name="rows1" match="row" use="id"/>
<xsl:key name="rows2" match="row" use="concat(id,'::',tag_name)"/>

<xsl:template match="page">
    <xsl:copy>
        <xsl:apply-templates select="rowset/row[count( . | key('rows1',
id)[1] ) = 1]" mode="rows1"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="row" mode="rows1">
    <individual id="{id}" name="{display_name}">
        <xsl:apply-templates select="key('rows1',id)[count( . | key('rows2',
concat(id,'::',tag_name))[1] ) = 1]" mode="rows2"/>
    </individual>
</xsl:template>

<xsl:template match="row" mode="rows2">
    <tag name="{tag_name}">
        <xsl:apply-templates select="key('rows2',
concat(id,'::',tag_name))"/>
    </tag>
</xsl:template>

<xsl:template match="row">
    <tmp name="{tmp_name}" score="{score}"/>
</xsl:template>

</xsl:stylesheet>

Hope this helps. But maybe it's better to use the SQL-solution provided by
Kirk.

Regards,

Joerg


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


Current Thread