xsl-list
[Top] [All Lists]

RE: [xsl] pairing up similar tags based on an attribute

2006-10-12 22:39:34
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(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com]
Sent: Thursday, October 12, 2006 1:52 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] 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[(_at_)parentpn="9310079"]/value
      spec[(_at_)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[(_at_)parentpn=$ppn]/value" />
   <xsl:text>
   </xsl:text>
</xsl:for-each-group>
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Webmaster <Webmaster(_at_)comtrol(_dot_)com>
Sent:     Wed, 11 Oct 2006 20:37:05 -0500
To:       "'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'" 
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  [xsl] 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[(_at_)partnumber=9300033]">
  <xsl:for-each select="./@parentpn">
      <xsl:message>
              <xsl:value-of select="ancestor::spec/value" />
              <xsl:value-of 
select="ancestor::spec[(_at_)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





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--