[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: "Jacoby, Peter R." <PJACOBY@xxxxxxxxxxxx>
Date: Mon, 3 May 2004 10:44:16 -0400
xml match
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


--------------------------------------------
This message contains useless information that may be confidential and
monotonous.  Unless you are the intended recipient, know the intended recipient
in the biblical sense, or are authorized to receive this message for the
intended recipient while the intended recipient is being lazy, you may not use,
abuse, copy, masticate, disseminate,  or disinter to anyone, including the
indented recipient, the message or any information contained in the
aforementioned message. If you have received the message in error, please advise
the sender by reply telegraph, blame your system administrator for all of the
world's problems, and delete the message immediately.  Thank you very much.
Have a good day.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.