Subject: Re: [xsl] Is it possible to group by name() ? From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 17 Sep 2002 19:05:44 -0400 |
I would appreciate some help on this. I have an XML that looks like this:
<n0> <n1> <a>text</a> <b>text</b> <c>text</c> </n1> <n1> <a>text</a> <c>text</c> </n1> <n1> <a>text</a> <b>text</b> <d>text</d> </n1> </n0>
And what I would like to have is a list of the different nodes inside n1 nodes. In the example above, the result should be: a,b,c,d.
Is it possible to do something like this ? <xsl:key name="groupbyname" match="/n0/n1/*" use="name()"/>
And then use the muenchian method ? But how ?
<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>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/> <!-- cleans things up a bit -->
<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>
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Is it possible to group by na, Casadome, Francisco | Thread | RE: [xsl] Is it possible to group b, Casadome, Francisco |
RE: [xsl] apache fop - formating qu, Wendell Piez | Date | RE: [xsl] href with & ?, Julian Reschke |
Month |