Subject: RE: [xsl] Grouping problem - Duplicates From: "Jacoby, Peter R." <PJACOBY@xxxxxxxxxxxx> Date: Mon, 3 May 2004 10:44:16 -0400 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping problem - Duplic, Sarah | Thread | RE: [xsl] Grouping problem - Duplic, Sarah |
Re: [xsl] Grouping problem - Duplic, Joseph Kesselman | Date | RE: Re: [xsl] how to split one xml , Qin Ding |
Month |