[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: pairing up similar tags based on an attribute

Subject: Re: pairing up similar tags based on an attribute
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Thu, 12 Oct 2006 11:06:55 +0300
Re:  pairing up similar tags based on an attribute
Hi,

It is not very clear for me what is your input and what is your output... Anyway, have a look at the following stylesheet, on your example it will output

pair(9300033,9300133) with common parent 9310079
pair(9300033,9300133) with common parent 9310023

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="specByParent" match="spec" use="@parentpn"/>
<xsl:template match="spec[@partnumber=9300033]">
<xsl:variable name="specs" select="key('specByParent', @parentpn)"/>
<xsl:text>pair(9300033,</xsl:text>
<xsl:value-of select="$specs[generate-id()!=generate-id(current())]/@partnumber"/>
<xsl:text>) with common parent </xsl:text>
<xsl:value-of select="@parentpn"/>
</xsl:template>
<xsl:template match="spec"/>
</xsl:stylesheet>


Hope that helps,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Webmaster wrote:
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.