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

XSLT: Selecting nodes based on a group of other nodes

Subject: XSLT: Selecting nodes based on a group of other nodes
From: "Mark Sztainbok" <sz@xxxxxxxxxxxxxx>
Date: Thu, 9 Sep 1999 15:41:04 +1000
xslt quoted printable
Is there a way to select nodes out of a document if they have a value which
matches a value in another group of nodes?

For example,

if I have a document which looks like this:

<RESPONSE>
    <PRODUCT>
        <ID>ABC</ID>
        <NAME>Brown dog</NAME>
    </PRODUCT>
    <PRODUCT>
        <ID>DEF</ID>
        <NAME>Black cat</NAME>
    </PRODUCT>
    <PRODUCT>
        <ID>GHI</ID>
        <NAME>Yellow giraffe</NAME>
    </PRODUCT>
    <PRODUCT>
        <ID>JKL</ID>
        <NAME>Orange monkey</NAME>
    </PRODUCT>
    <SELECTEDPRODUCT>ABC</SELECTEDPRODUCT>
    <SELECTEDPRODUCT>GHI</SELECTEDPRODUCT>
</RESPONSE>

I would like to get a node list of the products which have an ID which is in
a SELECTEDPRODUCT element i.e. products ABC and GHI (Brown dog and Yellow
giraffe) and store it in a variable so I can use it later with for-each

I have tried the following XSLT code but it doesn't work as it only gets the
first product:
<xsl:variable name="IDS" select="/RESPONSE/SELECTEDPRODUCT"/>
<xsl:variable name="products" select="/RESPONSE/PRODUCT[ID = $IDS]/>

and have also tried this, which also did not work:
<xsl:variable name="products"/>
<xsl:for-each select="RESPONSE/SELECTEDPRODUCT">
    <xsl:variable name="product_id" select="text()"/>
    <xsl:choose>
        <xsl:when test="$products">
            <xsl:variable name="products"
select="$products|/RESPONSE/PRODUCT[ID=$product_id])"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:variable name="products"
select="/RESPONSE/PRODUCT[ID=$product_id]"/>
        </xsl:otherwise>
   </xsl:choose>
</xsl:for-each>

What is the correct way to do this?

Thanks,

Mark


BEGIN:VCARD
VERSION:2.1
N:Sztainbok;Mark
FN:Mark Sztainbok
ORG:Sausage Software
TITLE:Software Engineer
TEL;WORK;VOICE:+61-3-9662 2627
TEL;WORK;FAX:+61-3-9663 4030
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;Level 25,=0D=0A150 Lonsdale Street;Melbourne;VIC;3000;Australia
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Level 25,=0D=0A150 Lonsdale Street=0D=0AMelbourne, VIC 3000=0D=0AAustralia
X-WAB-GENDER:2
URL:
URL:http://www.sausage.com
EMAIL;PREF;INTERNET:sz@xxxxxxxxxxxxxx
REV:19990909T054104Z
END:VCARD
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.