|
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 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: xsl:fo in web browsers, James Tauber | Thread | Re: XSLT: Selecting nodes based on , Miloslav Nic |
| XSL-FO tools/processors, Mahesh Nathan | Date | Re: XSLT: Selecting nodes based on , Miloslav Nic |
| Month |