Subject: RE: pairing up similar tags based on an attribute
From: Webmaster <Webmaster@xxxxxxxxxxx>
Date: Fri, 13 Oct 2006 00:39:10 -0500
|
Hi.All.
Thank you for your responses. It was really hard for me to explain my
situation, but I think you understood the question. I'm using XSL1.0, and am
pursueing the muechian method. And consequently pulling my hair out.
I'll let you know how it turns out.
> -----Original Message-----
> From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx]
> Sent: Thursday, October 12, 2006 1:52 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: pairing up similar tags based on an attribute
>
>
> I can't recall if you got an answer on this, but if not, I'll
> see how I can help.
>
> Let me re-state the situation and you can tell me if I got it
> right or how I got it wrong.
>
> o) You have a set of <spec> elements (not tags).
> o) Each <spec> element has two attributes: "partnumber" and
> "parentpn".
> o) For every distinct value of "spec/@parentpn", there are
> exactly two <spec> elements.
> o) For each distinct value of "parentpn", you want your
> stylesheet to emit the text node that is a child of the
> <value> element that, in turn, is a child of the <spec> element.
>
> i.e., spec[@parentpn="9310079"]/value
> spec[@parentpn="9310023"]/value
>
> The values of the "partnumber" attributes are a red herring,
> and don't fit into the XPath construction.
>
> Are you using XSLT 1.0 or XSLT 2.0?
>
> Here is an XST 2.0 construct that will do what you describe
> (as far as I can understand what you want.)
>
> <xsl:for-each-group select="spec" group-by="@parentpn">
> <xsl:variable name="ppn" select="@parentpn" />
> <xsl:value-of select="value" />:<xsl:value-of
> select="following-sibling::spec[@parentpn=$ppn]/value" />
> <xsl:text>
> </xsl:text>
> </xsl:for-each-group>
> --
> Charles Knell
> cknell@xxxxxxxxxx - email
>
>
>
> -----Original Message-----
> From: Webmaster <Webmaster@xxxxxxxxxxx>
> Sent: Wed, 11 Oct 2006 20:37:05 -0500
> To: "'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'"
> <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Subject: pairing up similar tags based on an attribute
>
> 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.
>
> Any help would be very much appreciated!!!
>
> LN
|