Re: XSLT: Selecting nodes based on a group of other nodes

Subject: Re: XSLT: Selecting nodes based on a group of other nodes
From: "Mark Sztainbok" <sz@xxxxxxxxxxxxxx>
Date: Fri, 10 Sep 1999 11:01:22 +1000
That's not exactly what I'm looking for. What I need to do is store the node
list into a variable so that something like the following can be done:

<xsl:choose>
    <xsl:when test="/RESPONSE/FILTERED">
        <!-- Set products variable to products that have corresponding
SELECTEDPRODUCT nodes -->
        <!-- Insert my attempts to code here -->
    </xsl:when>
    <xsl:otherwise>
        <!-- Set products variable to all the products -->
        <xsl:variable name="products" select="/RESPONSE/PRODUCT"/>
    </xsl:otherwise>
</xsl:choose>
<xsl:for-each select="$products">
    <!-- Process products here -->
</xsl:for-each>

Any ideas of how to set the products variable in the first case given the
description of what I want to do that I gave in my first email?

Thanks,

Mark

----- Original Message -----
From: Miloslav Nic <nicmila@xxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxx>
Sent: Thursday, September 09, 1999 4:58 PM
Subject: Re: XSLT: Selecting nodes based on a group of other nodes


> Look at http://zvon.vscht.cz/HTMLonly/XSLTutorial/Books/Book1/index.html
> example 75. It can help.
>
> Mark Sztainbok wrote:
> >
> > 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
>
> --
> ***************************************************************
> Dr. Miloslav Nic                        e-mail: nicmila@xxxxxxxx
> Department of Organic Chemistry         TEL: +420 2 2435 5012
> ICT Prague (VSCHT Praha)                     +420 2 2435 4118
>             FAX: +420 2 2435 4288
> ****************************************************************
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread