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

RE: matching on multiple attributes contained in a nod

Subject: RE: matching on multiple attributes contained in a node-set
From: Carl Yu <carl.yu@xxxxxxxxxxxx>
Date: Fri, 28 Mar 2003 09:16:55 -0800 (PST)
carl yu
Jarno,

Thanks to your re-organization of my implemtation I was able to discern a 
solution that works.  Here's what I ended up doing.

<?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="/dftml">
   <xsl:apply-templates select="student"/>
</xsl:template>

<xsl:template match="/dftml/student">
   <xsl:variable name="s" select="." />
   <xsl:variable name="validList">
      <xsl:for-each select="xalan:nodeset($list)/item[$s/grade/@value=@grade and 
$s/type/@value=@type]">
         <xsl:copy-of select="$s" />
      </xsl:for-each>
   </xsl:variable>

   <xsl:value-of select="name/@value"/>
   <xsl:choose>
      <xsl:when test="xalan:nodeset($validList)/node()">
         <xsl:text> is in the list.&#xA;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
         <xsl:text> is not in the list.&#xA;</xsl:text>
      </xsl:otherwise>
   </xsl:choose>

</xsl:template>

</xsl:transform>

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


>Date: Fri, 28 Mar 2003 08:37:49 -0800 (PST)
>From: Carl Yu <yuc>
>Subject: RE:  matching on multiple attributes contained in a node-set
>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>Cc: Jarno.Elovirta@xxxxxxxxx
>Mime-Version: 1.0
>Content-MD5: JHl6yh4PccBV0c1QU+vX0A==
>
>Thanks for cleaning up my implementation, but -- unfortunately, I'm looking 
>something that outputs 1 line for each and every student, not just the ones in 
>the list.  I've altered your implementation to do this... but it suffers from 
>the same problem as my initial implementation.
>

>[modified 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="dftml">
>  <xsl:for-each select="student">
>    <xsl:variable name="s" select="." />
>    <xsl:for-each select="xalan:nodeset($list)/item">
>      <xsl:choose>
>        <xsl:when test="$s/grade/@value = @grade and $s/type/@value = @type">
>         <xsl:value-of select="$s/name/@value" />
>         <xsl:text> is in the list.&#xA;</xsl:text>
>        </xsl:when>
>        <xsl:otherwise>
>         <xsl:value-of select="$s/name/@value" />
>         <xsl:text> is not in the list.&#xA;</xsl:text>
>        </xsl:otherwise>
>      </xsl:choose>
>    </xsl:for-each>
>  </xsl:for-each>
></xsl:template>
>
></xsl:transform>
>
>[output]
>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.
>
>[desired output]
>bob is not in the list.
>joe is not in the list.
>peter is not in the list.
>larry is in the list.
>
>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.