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

matching on multiple attributes contained in a node-se

Subject: matching on multiple attributes contained in a node-set
From: Carl Yu <carl.yu@xxxxxxxxxxxx>
Date: Thu, 27 Mar 2003 18:11:48 -0800 (PST)
xsl matching multiple attributes
Hi,

This seems like super easy problem, that I'm overthinking.  I really need some 
other eyeballs on it.

I'm trying to match items contained in a node-set (stored in a variable in the 
xsl file).  The trick is, the list contains sets of items that must be compared 
together.

Here are the files...
[in.xml]
<?xml version="1.0" encoding="UTF-8"?>
<dftml version="0.2">
  <student>
     <name value="bob"/>
     <grade value="1"/>
     <type="lunch"/>
  </student>
  <student>
     <name value="joe"/>
     <grade value="1"/>
     <type="science"/>
  </student>
  <student>
     <name value="peter"/>
     <grade value="2"/>
     <type="math"/>
  </student>
  <student>
     <name value="larry"/>
     <grade value="1"/>
     <type="math"/>
  </student>
</dftml>

[test.xsl]
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan" 
version="1.0">
<xsl:output method="text"/>

<xsl:variable name="list">
<item grade="1" type="math"/>
<item grade="2" type="science"/>
</xsl:variable>

<xsl:template match="/node()">
   <xsl:apply-templates select="/dftml/student"/>
</xsl:template>

<xsl:template match="/dftml/student">
   <xsl:variable name="this" select="self::node()"/>
   <xsl:for-each select="xalan:nodeset($list)/item">
      <xsl:variable name="item" select="self::node()"/>
      <xsl:element name="blah">
         <xsl:choose>
            <xsl:when test="$this/grade/@value=$item/@grade and 
$this/type/@value=$item/@type">
               <xsl:value-of select="$this/name/@value"/>
               <xsl:text> is in the list.
</xsl:text>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$this/name/@value"/>
               <xsl:text> is not in the list.
</xsl:text>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:element>
   </xsl:for-each>
</xsl:template>

</xsl:transform

[out.xml]
bob is not in the list.
bob is not in the list.
joe is not in the list.
joe is not in the list.
peter is not in the list.
peter is not in the list.
larry is in the list.
larry is not in the list.

The desired output would list all the students, but only once.  That is, larry 
is listed as being on the list, all others are not.

The variable $list can be variable in length.. that is, I may add or remove 
items from this list (in fact, in the real-deal, this is a passed-in parameter 
to the Transformer.)

When I first thought of this problem I though I could just use a simple match... 
why is the solution eluding me!  Arrgh.  In the case where there's only one item 
to match, this could be done using a simple match statement... the fact that 
there is a pair of items to match is tripping me up.

Please help!
Thanks,
Carl


 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.