XML Tutorials

  Home arrow XML Tutorials arrow Page 2 - Performing Set Operations When Queryin...
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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Performing Set Operations When Querying XML - Implementing the Recursive Templates


    (Page 2 of 4 )

    These recursive templates are implemented in terms of the following definitions:

    Union(nodes1,nodes2)
      
    The union includes everything innodes2plus
       everything innodes1not already a member of  
       nodes2.

    Intersection(nodes1,nodes2)
       The intersection includes everything innodes1that 
       is also a member ofnodes2.

    Difference(nodes1,nodes2)
      
    The difference includes everything innodes1that is
       not also a member ofnodes2.

    In all cases, membership defaults to equality of string values, but the importing stylesheet can override this default.

    Given these value-oriented set operations, you can achieve the desired effect on people1.xml and people2.xml using the following stylesheet:

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

      <xsl:import href="set.ops.xslt"/>

      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

      <xsl:template match="/">
       
    <people>
         
    <xsl:call-template name="vset:union">
           
    <xsl:with-param name="nodes1" select="//person"/>
           
    <xsl:with-param name="nodes2" select="document('people2.xml')//person"/>
         
    </xsl:call-template>
        </people>
      </xsl:template>

      <!--Define person equality as having the same name -->
      <xsl:template match="person" mode="vset:element-equality">
       
    <xsl:param name="other"/>
       
    <xsl:if test="@name = $other/@name">
         
    <xsl:value-of select="true()"/>
        </xsl:if>
      </xsl:template>

      </xsl:stylesheet>

    More XML Tutorials Articles
    More By O'Reilly Media

    blog comments powered by Disqus

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - 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-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap