XSLT

XSLT

3.0 6
by Doug Tidwell
     
 

View All Available Formats & Editions

XSLT documents a core technology for processing XML. Originally created for page layout, XSLT (Extensible Stylesheet Transformations) is now much more: a general-purpose translation tool, a system for reorganizing document content, and a way to generate multiple results— such as HTML, WAP, and SVG—from the same content.What sets XSLT

…  See more details below

Overview

XSLT documents a core technology for processing XML. Originally created for page layout, XSLT (Extensible Stylesheet Transformations) is now much more: a general-purpose translation tool, a system for reorganizing document content, and a way to generate multiple results— such as HTML, WAP, and SVG—from the same content.What sets XSLT apart from other books on this critical tool is the depth of detail and breadth of knowledge that Doug Tidwell, a developer with years of XSLT experience, brings to his concise treatment of the many talents of XSLT. He covers XSLT and XPath, a critical companion standard, and addresses topics ranging from basic transformations to complex sorting and linking. He explores extension functions on a variety of different XSLT processors and shows ways to combine multiple documents using XSLT. Code examples add a real-world dimension to each technique.Useful as XSLT is, its peculiar characteristics make it difficult to get started in, and the ability to use advanced techniques depends on a clear and exact understanding of how XSLT templates work and interact. For instance, the understanding of "variables" in XSLT is deeply different from the understanding of "variables" in procedural languages. The author explains XSLT by building from the basics to its more complex and powerful possibilities, so that whether you're just starting out in XSLT or looking for advanced techniques, you'll find the level of information you need.

Read More

Product Details

ISBN-13:
9780596000530
Publisher:
O'Reilly Media, Incorporated
Publication date:
09/07/2001
Edition description:
1 ED
Pages:
480
Product dimensions:
7.00(w) x 9.28(h) x 1.13(d)

Read an Excerpt

Chapter 5: Creating Links and Cross-References

Contents:

Generating Links with the id() Function
Generating Links with the key() Function
Generating Links in Unstructured Documents
Summary

If you're creating a web site, publishing a book, or creating an XML transaction, chances are many pieces of information will refer to other things. This chapter discusses a several ways to link XML elements. It reviews three techniques:

  • Using the id() function

  • Doing more advanced linking with the key() function

  • Generating links in unstructured documents

Generating Links with the id() Function

Our first attempt at linking will be with the XPath id() function.

The ID, IDREF, and IDREFs Datatypes

Three of the basic datatypes supported by XML Document Type Definitions (DTDs) are ID, IDREF, and IDREFS. Here's a simple DTD that illustrates these datatypes:

<!--glossary.dtd-->
<!--The containing tag for the entire glossary-->
<!ELEMENT glossary  (glentry+) >

<!--A glossary entry-->
<!ELEMENT glentry  (term,defn+) >

<!--The word being defined-->
<!ELEMENT term  (#PCDATA) >
<!--The id is used for cross-referencing, and the 
    xreftext is the text used by cross-references.-->
<!ATTLIST term
               id  ID    #REQUIRED 
               xreftext  CDATA    #IMPLIED  >

<!--The definition of the term-->
<!ELEMENT defn  (#PCDATA | xref | seealso)* >

<!--A cross-reference to another term-->
<!ELEMENT xref   EMPTY  >

<!--refid is the ID of the referenced term-->
<!ATTLIST xref
               refid  IDREF    #REQUIRED >

<!--seealso refers to one or more other definitions-->
<!ELEMENT seealso EMPTY>
<!ATTLIST seealso
                  refids   IDREFS  #REQUIRED >

In this DTD, each <term> element is required to have an id attribute, and each <xref> element must have an refid attribute. The ID and IDREF datatypes work according to two rules:

  • Each value of the id attribute must be unique.

  • Each value of the refid attribute must match a value of an id attribute elsewhere in the document.

To round out our example, the <seealso> element contains an attribute of type IDREFS. This datatype contains one or more values, each of which must match a value of an ID elsewhere in the document. Multiple values, if present, are separated by whitespace.

There are some complications of ID and related datatypes, but we'll discuss them later. For now, we'll focus on how the id() function works.

An XML Document in Need of Links

To illustrate the value of linking, we'll use a small glossary written in XML. The glossary contains some <glentry> elements, each of which contains a single <term> and one or more <defn> elements. In addition, a definition is allowed to contain a cross-reference (<xref>) to another <term>. Here's a short sample document:

<?xml version="1.0" ?>
<!DOCTYPE glossary SYSTEM "glossary.dtd">
<glossary>
  <glentry>
    <term id="applet">applet</term>
    <defn>
      An application program,
      written in the Java programming language, that can be 
      retrieved from a web server and executed by a web browser. 
      A reference to an applet appears in the markup for a web 
      page, in the same way that a reference to a graphics
      file appears; a browser retrieves an applet in the same 
      way that it retrieves a graphics file. 
      For security reasons, an applet's access rights are limited
      in two ways: the applet cannot access the file system of the 
      client upon which it is executing, and the applet's 
      communication across the network is limited to the server 
      from which it was downloaded. 
      Contrast with <xref refid="servlet"/>.
      <seealso refids="wildcard-char DMZlong pattern-matching"/>
    </defn>
  </glentry>

  <glentry>
    <term id="DMZlong" xreftext="demilitarized zone">demilitarized 
      zone (DMZ)</term>
    <defn>
      In network security, a network that is isolated from, and 
      serves as a neutral zone between, a trusted network (for example, 
      a private intranet) and an untrusted network (for example, the
      Internet). One or more secure gateways usually control access 
      to the DMZ from the trusted or the untrusted network.
    </defn>
  </glentry>

  <glentry>
    <term id="DMZ">DMZ</term>
    <defn>
      See <xref refid="DMZlong"/>.
    </defn>
  </glentry>

  <glentry>
    <term id="pattern-matching">pattern-matching character</term>
    <defn>
      A special character such as an asterisk (*) or a question mark 
      (?) that can be used to represent zero or more characters. 
      Any character or set of characters can replace a pattern-matching 
      character.
    </defn>
  </glentry>

  <glentry>
    <term id="servlet">servlet</term>
    <defn>
      An application program, written in the Java programming language, 
      that is executed on a web server. A reference to a servlet 
      appears in the markup for a web page, in the same way that a 
      reference to a graphics file appears. The web server executes
      the servlet and sends the results of the execution (if there are
      any) to the web browser. Contrast with <xref refid="applet" />.
    </defn>
  </glentry>

  <glentry>
    <term id="wildcard-char">wildcard character</term>
    <defn>
      See <xref refid="pattern-matching"/>.
    </defn>
  </glentry>
</glossary>

In this XML listing, each <term> element has an id attribute that identifies it uniquely. Many <xref> elements also refer to other terms in the listing. Notice that each time we refer to another term, we don't use the actual text of the referenced term. When we write our stylesheet, we'll use the XPath id function to retrieve the text of the referenced term; if the name of a term changes (as buzzwords go in and out of fashion, some marketing genius might want to rename the "pattern-matching character," for example), we can rerun our stylesheet and be confident that all references to the new term contain the correct text.

Finally, some <term> elements have an xreftext element because some of the actual terms are longer than we'd like to use in a cross-reference. When we have an <xref> to the term ASCII (American Standard Code for Information Interchange), it would get pretty tedious if the entire text of the term appeared throughout our document. For this term, we'll use the xreftext attribute's value, ensuring that the cross-reference contains the less-intimidating text ASCII....

Read More

Meet the Author

Doug Tidwell is a senior programmer at IBM. He has more than a sixth of a century of programming experience, and has been working with markup languages for more than a decade. He was a speaker at the first XML conference in 1997, and has taught XML classes around the world. His job as a Cyber Evangelist is to look busy and to help people use new technologies to solve problems. Using a pair of zircon-encrusted tweezers, he holds a master's degree in computer science from Vanderbilt University and a bachelor's degree in English from the University of Georgia. He lives in Raleigh, North Carolina, with his wife, cooking teacher Sheri Castle (see her web site at http://www.sheri-inc.com) and their daughter Lily.

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >

XSLT 3 out of 5 based on 0 ratings. 6 reviews.
Guest More than 1 year ago
Although Tidwell emphasizes a real-world approach to tackling XSLT and includes plenty of practical examples in the book, he doesn't skimp when it comes to delivering the types of conceptual explanations (sections like 'How a Stylesheet is processed' in Chpt 2 and 'The XPath View of an XML Document' in Chpt. 3) that help readers understand what's going on 'under the hood'. Including a separate chapter covering the basics of XPath early in the book also makes for much easier reading, since we aren't left scrounging for scraps of information scattered throughout the text when XPath-related questions arise. If not for the fact that some authors have actually taken the opposite approach (introducing XPath concepts as they arise in the context of a discussion of XSLT), this would have seemed like a no-brainer. No review of this book would be complete without mentioning the value added by the appendices. Once you've digested all of the material in the body of the text, you'll likely continue to keep Tidwell's book close at hand because of Appendices A and C. Appendix A, the XSLT Reference, features a comprehensive dictionary-style reference for every element in XSLT 1.0 - including an XML source document, an example stylesheet that makes use of the element, and the result of the transformation for each. Appendix C, the XSLT and XPath Function Reference, follows a similar format.
Anonymous More than 1 year ago
XSLT and related technology are sufficiently different from typical programming lanuages that they benefit from explanations that are careful, precise, and free of ambiguity. This is not such a book. It is full of careless phrasing, ambiguities, puzzling logic, and poorly chosen analogies. Frequently while reading it I wanted to throw it across the room.
Anonymous More than 1 year ago
Anonymous More than 1 year ago
Anonymous More than 1 year ago
Anonymous More than 1 year ago