Subject: Re: [xsl] Muenchian grouping with either attribute From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 14 Sep 2006 16:04:23 +0100 |
> I know that the standard answer in cases like this is "do the > Muenchian". But all the examples I've found deal with the Muenchian > over elements, whereas here, I need a Muenchian on the combination of > attr1 and attr2. xpath by design aims to treat attributes and elements as equally as possible, so basically grouping attribute nodes works the same way as grouping element nodes but you just need to add a @ something like this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:key name="p" match="@*" use="."/> <xsl:key name="pn" match="@*" use="concat(name(),':',.)"/> <xsl:template match="/"> <properties> <xsl:for-each select="root/item/property/@*[generate-id()=generate-id(key('p',.))]"> <property name="{.}" > <xsl:for-each select="key('p',.)[generate-id()=generate-id(key('pn',concat(name(),':',.)))]"> <xsl:attribute name="freq_{name()}"> <xsl:value-of select="count(key('pn',concat(name(),':',.)))"/> </xsl:attribute> </xsl:for-each> </property> </xsl:for-each> </properties> </xsl:template> </xsl:stylesheet> $ saxon prop.xml prop.xsl <?xml version="1.0" encoding="utf-8"?> <properties> <property name="foo" freq_attr1="1" freq_attr2="1"/> <property name="bar" freq_attr2="1" freq_attr1="2"/> <property name="baz" freq_attr2="1"/> </properties>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Muenchian grouping with eithe, Jack Tanner | Thread | [xsl] text nodes not merged, Wolfgang Jeltsch |
Re: [xsl] SSI echo as an attribute , tom tom | Date | Re: [xsl] SSI echo as an attribute , David Carlisle |
Month |