XML Tutorials
  Home arrow XML Tutorials arrow Page 4 - Querying XML
IBM Developerworks
The Best Selling PC Migration Utility.
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 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
IBM Developerworks
 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

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

    Table of Contents:
  • Querying XML
  • 9.1 Performing Set Operations on Node Sets
  • Performing Set Operations on Node Sets continued
  • 9.2 Performing Set Operations on Node Sets Using Value Semantics

  • 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
     
     
    FaxWave - Free Trial.
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Querying XML - 9.2 Performing Set Operations on Node Sets Using Value Semantics
    (Page 4 of 4 )

    Problem

    You need to find the union, intersection, set difference, or symmetrical set difference between elements in two node sets; however, in your problem, equality is not defined as node-set identity. In other words, equality is a function of a node’s value.

    Solution

    XSLT 1.0

    The need for this solution may arise when working with multiple documents. Consider two documents with the same DTD but content that may not contain duplicate element values. XSLT elements coming from distinct documents are distinct even if they contain elements with the same namespace, attribute, and text values. See Examples 9-1 to 9-4.

    Example 9-1. people1.xslt

    <people>
      <person name="Brad York" age="38" sex="m" smoker="yes"/>
      <person name="Charles Xavier" age="32" sex="m" smoker="no"/>
      <person name="David Williams" age="33" sex="m" smoker="no"/>
    </people>

    Example 9-2. people2.xslt

    <people>
      <person name="Al Zehtooney" age="33" sex="m" smoker="no"/>
      <person name="Brad York" age="38" sex="m" smoker="yes"/>
      <person name="Charles Xavier" age="32" sex="m" smoker="no"/>
    </people>

    Example 9-3. Failed attempt to use XSLT union to select unique people

    <xsl:template match="/">
      <people>
        <xsl:copy-of select="//person | document('people2.xml')//person"/>
      </people>
    </xsl:template>

    Example 9-4. Output when run with people1.xml as input

    <people>
       <person name="Brad York" age="38" sex="m" smoker="yes"/>
       <person name="Charles Xavier" age="32" sex="m" smoker="no"/>
       <person name="David Williams" age="33" sex="m" smoker="no"/>
       <person name="Al Zehtooney" age="33" sex="m" smoker="no"/>
       <person name="Brad York" age="38" sex="m" smoker="yes"/>
       <person name="Charles Xavier" age="32" sex="m" smoker="no"/>
    </people>

    Relying on node identity can also break down in single document cases when you want equality of nodes to be a function of their text or attribute values.

    Please check back next week for the continuation of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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

    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


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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