|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Is it possible to group by name() ?
Frank,
At 04:54 PM 9/17/2002, you wrote: I would appreciate some help on this. I have an XML that looks like this: You're right on track. When using the Muenchian method, remember it works by doing two things. First, grouping, which you have down (your key does this). Then, de-duplicating by picking one node from each group -- using it to fire off processing the whole group if necessary (in your case it's not). Once you've mastered the two steps, it's only a matter of deciding how you want to traverse your nodes to get to them. So you could do: <xsl:for-each select="/n0/n1/*">
<!-- iterates over all the candidate nodes -->
<xsl:if test="count(.|key('groupbyname', name())[1]) = 1">
<!-- throws away all but the first of each group -->
<xsl:value-of select="name()"/>
<!-- outputs the name you want -->
</xsl:if>
</xsl:for-each>Similarly, an entire stylesheet could look like: <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="text"/> <xsl:strip-space elements="*"/> <!-- cleans things up a bit --> <xsl:key name="groupbyname" match="/n0/n1/*" use="name()"/> <xsl:template match="/n0/n1/*[count(.|key('groupbyname', name())[1]) = 1]">
<!-- puts the selection logic into a template match -->
<xsl:value-of select="concat(name(), '
')"/>
<!-- inserting an extra line break for clarity -->
</xsl:template><xsl:template match="text()"> <!-- suppress text nodes as uninteresting --> </xsl:template> </xsl:stylesheet> Fun, huh? Cheers, Wendell
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|

Cart








