[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
RE: Grouping problem - Duplicates
Subject: RE: Grouping problem - Duplicates
From: Sarah <sarah10@xxxxxxxxxxx>
Date: Mon, 03 May 2004 20:20:45 +0200
|
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|