XML Tutorials
  Home arrow XML Tutorials arrow Page 4 - Solving Problems by Querying XML
eWeek
FaxWave - Free Trial.
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 
 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

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

    Table of Contents:
  • Solving Problems by Querying XML
  • 9.4 Performing Structure-Preserving Queries
  • 9.5 Joins
  • Joins With Many Members

  • 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
     
     
    The Best Selling PC Migration Utility.
     
    ADVERTISEMENT

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Building a Virtual Infrastructure from Servers to Storage by Network Appliance

    Solving Problems by Querying XML - Joins With Many Members
    (Page 4 of 4 )

    If one of the sets of elements to be joined has a large number of members, then consider usingxsl:keyto improve performance:

      <xsl:key name="part-city" match="part" use="@city"/>

      <xsl:template match="/">
        <result>
          <xsl:for-each select="database/suppliers/*">
            <xsl:variable name="supplier" select="."/>
            <xsl:for-each select="key('part-city',$supplier/@city)">
            <colocated>
              <xsl:copy-of select="$supplier"/>
              <xsl:copy-of select="."/>
            </colocated>
            </xsl:for-each>
          </xsl:for-each>
        </result>
      </xsl:template>

    Each stylesheet produces the same result:

      <result>
       
    <colocated>
          <supplier id="S1" name="Smith" status="20" city="London"/>
          <part id="P1" name="Nut" color="Red" weight="12" city="London"/>
        </colocated>
       
    <colocated>
          <supplier id="S1" name="Smith" status="20" city="London"/>
          <part id="P4" name="Screw" color="Red" weight="14" city="London"/>
       
    </colocated>
       
    <colocated>
          <supplier id="S1" name="Smith" status="20" city="London"/>
          <part id="P6" name="Cog" color="Red" weight="19" city="London"/>
        </colocated>
       
    <colocated>
          <supplier id="S2" name="Jones" status="10" city="Paris"/>
          <part id="P2" name="Bult" color="Green" weight="17" city="Paris"/>
       
    </colocated>
       
    <colocated>
          <supplier id="S2" name="Jones" status="10" city="Paris"/>
          <part id="P5" name="Cam" color="Blue" weight="12" city="Paris"/>
       
    </colocated>
       
    <colocated>
          <supplier id="S3" name="Blake" status="30" city="Paris"/>
          <part id="P2" name="Bult" color="Green" weight="17" city="Paris"/>
       
    </colocated>
       
    <colocated>
          <supplier id="S3" name="Blake" status="30" city="Paris"/>
          <part id="P5" name="Cam" color="Blue" weight="12" city="Paris"/>
       
    </colocated>
       
    <colocated>
          <supplier id="S4" name="Clark" status="20" city="London"/>
          <part id="P1" name="Nut" color="Red" weight="12" city="London"/>
        </colocated>
       
    <colocated>
          <supplier id="S4" name="Clark" status="20" city="London"/>
          <part id="P4" name="Screw" color="Red" weight="14" city="London"/>
       
    </colocated>
       
    <colocated>
          <supplier id="S4" name="Clark" status="20" city="London"/>
          <part id="P6" name="Cog" color="Red" weight="19" city="London"/>
       
    </colocated>
      </result>

    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 "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 2 hosted by Hostway