Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Grouping problem - Duplicates

From: Sarah <sarah10@----------->
To:
Date: 5/3/2004 10:21:00 PM
Hi Peter.
That works great.
Thanks for the help and the good will.
:-)
Sarah

At 16:44 3/5/2004, you wrote:
Sarah,



>> Thanks for the xslt, but the thing is, you referred to the content of the

<Area>

>> node-names as hard coded, while I cannot do that.

>> The point is that it should be generic, and collect whatever might 
appear in

the

>> <Area> section. The XML is just a snipped example of the real content.



Ok, that makes sense, here is the modified solution that should be more 
generic.

It uses a key defined to find the first of each type of child nodes of 
Area.  It

then apply templates based on any of the nodes that match that current 
name.  If

your XML uses namespaces, you should change the references from name() to

local-name().



If you have any other questions, don't hesitate to ask.



<?xml version="1.0" ?>

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

<xsl:output method="xml" omit-xml-declaration="no" indent="yes"

encoding="UTF-8"/>



<xsl:key name="byName" match="Area/*" use="name()" />



<xsl:template match="/">
        <xsl:apply-templates select="Company"/>
</xsl:template>

<xsl:template match="Company">
        <div>
                <h1>Sales People by Areas</h1>
                <xsl:apply-templates select="Suppliers/Area" />
        </div>
</xsl:template>

<xsl:template match="Area">

        <xsl:apply-templates select="*[count(. | key('byName', 
name())[1]) = 1]"

/>

</xsl:template>



<xsl:template match="Area/*">
        <xsl:variable name="curName" select="name()" />
        <p>
                <xsl:value-of select="$curName" />
                <xsl:apply-templates
select="../../SalesPeople/SalesPerson[Supplier = current()/../*[name() =
$curName]]" />
        </p>
</xsl:template>

<xsl:template match="SalesPerson">
        <p>
                <xsl:value-of select="Name/FirstName" />
                <xsl:text> </xsl:text>
                <xsl:value-of select="Name/LastName" />
        </p>
</xsl:template>

</xsl:stylesheet>




-Peter


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent