Subject: Re: [xsl] pairing up similar tags based on an attribute From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Thu, 12 Oct 2006 09:05:22 +0100 |
Hello.
My data (snippet) looks like this:
<spec partnumber="9300033" parentpn="9310079"> <value>DB9</value> </spec>
<spec partnumber="9300133" parentpn="9310079"> <value>M</value> </spec>
<spec partnumber="9300033" parentpn="9310023"> <value>RJ45</value> </spec>
<spec partnumber="9300133" parentpn="9310023"> <value>F</value> </spec>
I'm trying to write a template that prints out each pair of 9300033 and 9300133 with the same @parentpn, but without luck:
<xsl:variable name="connectortype" > <xsl:for-each select="spec[@partnumber=9300033]"> <xsl:for-each select="./@parentpn"> <xsl:message> <xsl:value-of select="ancestor::spec/value" /> <xsl:value-of select="ancestor::spec[@partnumber=9300133 and @parentpn=.]/value" /> </xsl:message> </xsl:for-each> </xsl:for-each> </xsl:variable>
With this code, I'm getting the correct value for the 9300033, but I can't seem to grab the corresponding 9300133 value. I'm not quite sure if my xpath is right.
This is a grouping issue. If you are using 1.0 then you'll need to use the ominously titled "muenchian grouping" (http://www.jenitennison.com/xslt/grouping/index.xml)
<xsl:for-each-group select="spec" group-by="@parentpn"> <group> <xsl:apply-templates select="current-group()[@partnumber = ('9300033', '9300133')]"/> </group> </xsl:for-each-group>
cheers andrew
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] pairing up similar tags based, Webmaster | Thread | Re: [xsl] pairing up similar tags b, George Cristian Bina |
[xsl] pairing up similar tags based, Webmaster | Date | Re: [xsl] pairing up similar tags b, George Cristian Bina |
Month |