XML Tutorials

  Home arrow XML Tutorials arrow Page 2 - Querying XML: Use Cases
XML TUTORIALS

Querying XML: Use Cases
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2008-02-14

    Table of Contents:
  • Querying XML: Use Cases
  • Use case SGML: Standard Generalized Markup Language.
  • Use case PARTS: recursive parts explosion.
  • Use case REF: queries based on references.
  • Further Discussion of the W3C XML Query-Use Cases in XSLT

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Querying XML: Use Cases - Use case SGML: Standard Generalized Markup Language.


    (Page 2 of 5 )



    The example document and queries in this use case were first created for a 1992 conference on Standard Generalized Markup Language (SGML). For your use, the Document Type Definition (DTD) and example document are translated from SGML to XML.

    This chapter does not implement these queries because they are not significantly different from queries in other use cases. 

    Use case “TEXT”: full-text search.

    This use case is based on company profiles and a set of news documents that contain data for PR, mergers, and acquisitions. Given a company, the use case illustrates several different queries for searching text in news documents and different ways of providing query results by matching the information from the company profile and news content.

    In this use case, searches for company names are interpreted as word-based. The words in a company name may be in any case and separated by any kind of whitespace.

    All queries can be expressed in XSLT 1.0. However, doing so can result in the need for a lot of text-search machinery. For example, the most difficult queries require a mechanism for testing the existence of any member of a set of text values in another string. Furthermore, many queries require testing of text subunits, such as sentence boundaries.

    Based on techniques covered in Chapter 1, it should be clear that these problems have solutions in XSLT. However, if you will do a lot of text querying in XSLT, you will need a generic library of text-search utilities. Developing generic libraries is the focus of Chapter 14, which will revisit some of the most complex full-text queries. For now, you will solve two of the most straightforward text-search problems in the W3C document. This chapter lists the others to give a sense of why these queries can be challenging for XSLT 1.0. The difficult parts are emphasized.

    Question 1. Find all news items in which the name "Foobar Corporation" appears in the
    title:
     
    <xsl:template match="news">
      <result>
        <xsl:copy-of select="news_item/title[contains(., 'Foobar Corporation')]"/>
      </result>
      </xsl:template>
    Question 2. For each news item that is relevant to the Gorilla Corporation, create an
    "item summary" element. The content of the item summary is the title, date, and first
    paragraph of the news item, separated by periods. A news item is relevant if the name
    of the company is mentioned anywhere within the content of the news item:
     
    <xsl:template match="news">
      <result>
        <xsl:for-each select="news_item[contains(content,'Gorilla Corporation')]">
          <item_summary>
            <xsl:value-of select="normalize-space(title)"/>. <xsl:text/>
            <xsl:value-of select="normalize-space(date)"/>. <xsl:text/>
            <xsl:value-of select="normalize-space(content/par[1])"/>
          </item_summary>
        </xsl:for-each>
      </result>
      </xsl:template> 

    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 8 - Follow our Sitemap