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

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

Subject: Re: XSLT: Selecting nodes based on a group of other nodes
From: Miloslav Nic <nicmila@xxxxxxxx>
Date: Fri, 10 Sep 1999 08:06:30 +0200
xslt group operation
I am afraid you cannot but I would love to have this possibility in
XSLT:

XSLT draft:
Variables introduce an additional data-type into the expression
language. This additional data type is called result tree fragment. A
variable may be bound to a result tree fragment instead of one of the
four basic XPath data-types (string, number, boolean, node-set). A
result tree fragment represents a fragment of the result tree. A result
tree fragment is treated equivalently to a node-set that contains just a
single root node. However, the operations permitted on a result tree
fragment are a subset of those permitted on a node-set. An operation is
permitted on a result tree fragment only if that operation would be
permitted on a string (the operation on the string may involve first
converting the string to a number or boolean). In particular, it is not
permitted to use the /, //, and [] operators on result tree fragments.
When a permitted operation is performed on a result tree fragment, it is
performed exactly as it would be on the equivalent node-set.

Mark Sztainbok wrote:
> 
> 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

-- 
***************************************************************
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


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.