Subject: RE: [xsl] 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
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Grouping problem - Duplic, Jacoby, Peter R. | Thread | [xsl] getting the attribute into th, Toma Tasovac |
Re: [xsl] Grouping problem - Duplic, Sarah | Date | RE: [xsl] Inserting White Space (&n, Wendell Piez |
Month |