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

Re: Using "except" with node sequences

Subject: Re: Using "except" with node sequences
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 04 Aug 2008 13:55:28 -0400
Re:  Using "except" with node sequences
At 2008-08-04 12:38 -0500, James Sulak wrote:
I have a sequence of nodes stored in a variable,

Perhaps you only have a tree and not a sequence of nodes.


and I am attempting to filter it using an XPath expression that includes the "except" operator. However, it's not working like I expect it to.
...
I am attempting to filter it using this logic:


<olddata>
<xsl:sequence select="$normalized_data[not(info/@action='delete')] except $normalized_data[info/@action='insert' or info/@action='modify']" />
</olddata>


I expect the returned sequence to include all of the nodes in $normalized_data that match the first condition and don't match the second condition (node 3). What I am actually getting is all of the nodes in $normalized data. Is there something about the "except" operator that I'm not understanding?

Nope! Just a declaration issue I think.


You don't show your declaration of $normalized_data, so I'm going to assume you just made it a temporary tree and you didn't make it a variable of "data" elements.

My students of XSLT 2 who know XSLT 1 have had a problem with this when jumping on the temporary tree bandwagon, thinking they are getting variables of nodes, until I tell them about the use of the as= to direct the processor in the expected use of the variable.

I hope the example below helps illustrate the difference ... please let me know if this is not the source of your problem. You can see the only difference is how I declared the nodes stored in the variable.

. . . . . . . . . . . Ken


T:\ftemp>type james.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:output indent="yes"/>

<xsl:variable name="normalized_data">
<data id="1">
   <info action="delete" />
   <info action="insert" />
   <stuff />
</data>
<data id="2">
   <info action="insert" />
   <stuff />
</data>
<data id="3">
   <stuff />
</data>
</xsl:variable>

<xsl:variable name="normalized_data_ken" as="element(data)+">
<data id="1">
   <info action="delete" />
   <info action="insert" />
   <stuff />
</data>
<data id="2">
   <info action="insert" />
   <stuff />
</data>
<data id="3">
   <stuff />
</data>
</xsl:variable>

<xsl:template match="/">
<results>
<james>
<olddata>
<xsl:sequence select="$normalized_data[not(info/@action='delete')] except $normalized_data[info/@action='insert' or info/@action='modify']" />
</olddata>
</james>
<ken>
<xsl:sequence select="$normalized_data_ken[not(info/@action='delete')] except $normalized_data_ken[info/@action='insert' or info/@action='modify']" />
</ken>
</results>
</xsl:template>


</xsl:stylesheet>
T:\ftemp>call xslt2 james.xsl james.xsl james.xml

T:\ftemp>type james.xml
<?xml version="1.0" encoding="UTF-8"?>
<results>
   <james>
      <olddata>
         <data id="1">
            <info action="delete"/>
            <info action="insert"/>
            <stuff/>
         </data>
         <data id="2">
            <info action="insert"/>
            <stuff/>
         </data>
         <data id="3">
            <stuff/>
         </data>
      </olddata>
   </james>
   <ken>
      <data id="3">
         <stuff/>
      </data>
   </ken>
</results>
T:\ftemp>rem Done!


-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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-2011 All Rights Reserved.