XML Tutorials
  Home arrow XML Tutorials arrow Page 3 - Performing Set Operations When Querying XML
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML TUTORIALS

Performing Set Operations When Querying XML
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-01-24

    Table of Contents:
  • Performing Set Operations When Querying XML
  • Implementing the Recursive Templates
  • XSLT 2.0 Enhancements
  • Equality in Programming

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Performing Set Operations When Querying XML - XSLT 2.0 Enhancements


    (Page 3 of 4 )

    The main enhancement of XSLT 2.0 is to take advantage of the availability of first-class functions and sequences. This eliminates the need for recursion, the call-back trick, and leads to cleaner definitions and usage. The functions vset:element-equality and vset:member-ofcan still be overridden in importing stylesheets to customize behavior.

      <xsl:stylesheet version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/ Transform"
      xmlns:xs="http://www.w3.org/2001/ XMLSchema"
      xmlns:vset="http:/www.ora.com/XSLTCookbook/ namespaces/vset">

      <!-- The default implementation of element equality. Override in the importing
      stylesheet as necessary. -->
      <xsl:function name="vset:element-equality" as="xs:boolean">
       
    <xsl:param name="item1" as="item()?"/>
        <xsl:param name="item2" as="item()?"/>
        <xsl:sequence select="$item1 = $item2"/>
      </xsl:function>

      <!-- The default set membership test uses element equality. You will rarely need to
      override this in the importing stylesheet. -->
      <xsl:function name="vset:member-of" as="xs:boolean">
        <xsl:param name="set" as="item()*"/>
        <xsl:param name="elem" as="item()"/>
        <xsl:variable name="member-of" as="xs:boolean*"
                            
    select="for $test in $set
                return if (vset:element-equality($test, $elem))
                          then true() else ()"/>
        <xsl:sequence select="not(empty($member-of))"/>
      </xsl:function>

      <!-- Compute the union of two sets using "by value" equality. -->
      <xsl:function name="vset:union" as="item()*">
        <xsl:param name="nodes1" as="item()*" />
        <xsl:param name="nodes2" as="item()*" />
       
    <xsl:sequence select="$nodes1, for $test in $nodes2
                       return if (vset:member-of($nodes1,$test))
                           then () else $test"/>
      </xsl:function>

      <!-- Compute the intersection of two sets using "by value" equality. -->
      <xsl:function name="vset:intersection" as="item()*">
        <xsl:param name="nodes1" as="item()*" />
        <xsl:param name="nodes2" as="item()*" />
      
    <xsl:sequence select="for $test in $nodes1
                       return if (vset:member-of($nodes2,$test))
                           then $test else ()"/>
      </xsl:function>

      <!-- Compute the difference between two sets (node1 - nodes2) using "by value"
      equality. -->

      <xsl:function name="vset:difference" as="item()*">
        <xsl:param name="nodes1" as="item()*" />
        <xsl:param name="nodes2" as="item()*" />
       <xsl:sequence select="for $test in $nodes1 return if (vset:member-of($nodes2,$test))
      then () else $test"/>
      </xsl:function>

      </xsl:stylesheet>

    More XML Tutorials Articles
    More By O'Reilly Media


       · This article is an excerpt from the "XSLT Cookbook, Second Edition," published by...
     

    Buy this book now. This article is excerpted from chapter nine of the XSLT Cookbook, Second Edition, written by Sal Mangano (O'Reilly; ISBN: 0596009747). Check it out today at your favorite bookstore. Buy this book now.

    XML TUTORIALS ARTICLES

    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT