Summary Branching and Control Elements
Chapter 5. Creating Links and Cross-References
If youre 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 documents5.1 Generating Links with the id Function
Our first attempt at linking will be with the XPath id function.5.1.1 The ID, IDREF, and IDREFs Datatypes
Three of the basic datatypes supported by XML Document Type Definitions DTDs are ID , IDREF , and IDREFS . Heres 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. page 83 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 well discuss them later. For now, well focus on how the id function works.5.1.2 An XML Document in Need of Links
To illustrate the value of linking, well 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 . Heres a short sample document: ?xml version=1.0 ? DOCTYPE glossary SYSTEM glossary.dtd glossary glentry term id=appletappletterm 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 applets access rights are limited in two ways: the applet cannot access the file system of the client upon which it is executing, and the applets 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 zonedemilitarized zone DMZterm 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=DMZDMZterm defn See xref refid=DMZlong. defn glentry glentry term id=pattern-matchingpattern-matching characterterm 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 glentryParts
» O'Reilly-XSLT-Mastering.XML.Transformati... 2264KB Mar 29 2010 05:03:43 AM
» An XML document must be contained in a single element
» XML declarations Document Type Definitions DTDs and XML Schemas
» Well-formed versus valid documents
» Tags versus elements XML Document Rules
» Namespaces XML Document Rules
» The Extensible Stylesheet Language XSL
» Document Object Model DOM Level 1
» Document Object Model DOM Level 2
» Namespaces in XML XML Standards
» Associating stylesheets with XML documents
» Installing Xalan Getting Started
» Our Sample Document A Sample Stylesheet
» Transforming the XML Document
» Stylesheet Results Transforming Hello World
» Parsing the Stylesheet How a Stylesheet Is Processed
» Parsing the Transformee How a Stylesheet Is Processed
» Lather, Rinse, Repeat How a Stylesheet Is Processed
» The xsl:template for greeting Elements
» Built-in template rule for element and root nodes
» Built-in template rule for modes
» Built-in template rule for text and attribute nodes
» Top-Level Elements Stylesheet Structure
» Other Approaches Stylesheet Structure
» The Hello World Java Program
» Goals of This Chapter Summary
» The Root Node The XPath Data Model
» Element Nodes The XPath Data Model
» Attribute Nodes The XPath Data Model
» Text Nodes The XPath Data Model
» Comment Nodes The XPath Data Model
» Processing Instruction Nodes The XPath Data Model
» Namespace Nodes The XPath Data Model
» Simple Location Paths Location Paths
» Relative and Absolute Expressions
» Selecting attributes Selecting Things Besides Elements with Location Paths
» Selecting the text of an element
» Selecting comments, processing instructions, and namespace nodes
» Using Wildcards Location Paths
» Numbers in predicates Predicates
» Functions in predicates Predicates
» Attribute Value Templates XPath Datatypes
» Output View The XPath View of an XML Document
» The Stylesheet The XPath View of an XML Document
» Summary XPath: A Syntax for Describing Needles and Haystacks
» Converting to boolean values
» Boolean examples The xsl:if Element
» xsl:for-each example The xsl:for-each Element
» How It Works Invoking Templates by Name
» Templates à la Mode Invoking Templates by Name
» Defining a Parameter in a Template
» Microsofts XSLT tools Global Parameters
» Setting global parameters in a Java program
» Are These Things Really Variables?
» Procedural design Implementing a String Replace Function
» Recursive design Implementing a String Replace Function
» Template Design Implementation A Stylesheet That Emulates a for Loop
» The Complete Example A Stylesheet That Emulates a for Loop
» XML Input A Stylesheet That Generates a Stylesheet That Emulates a for Loop
» Template Design A Stylesheet That Generates a Stylesheet That Emulates a for Loop
» Complications A Stylesheet That Generates a Stylesheet That Emulates a for Loop
» Summary Branching and Control Elements
» The ID, IDREF, and IDREFs Datatypes
» An XML Document in Need of Links
» A Stylesheet That Uses the id Function
» Limitations of IDs Generating Links with the id Function
» Defining a key Generating Links with the key Function
» A Slightly More Complicated XML Document in Need of Links
» The key function and the IDREFS datatype
» Solution 1: Replace the IDREFS datatype
» Solution 2: Use the XPath contains function
» Solution 3: Use recursion to process the IDREFS datatype
» Solution 4: Use an extension function
» Advantages of the key Function
» An Unstructured XML Document in Need of Links
» The generate-id Function Generating Links in Unstructured Documents
» Summary Creating Links and Cross-References
» Our First Example Sorting Data with xsl:sort
» Whats the deal with that syntax?
» Attributes The Details on the xsl:sort Element
» Another Example Sorting Data with xsl:sort
» Our First Attempt Grouping Nodes
» A Brute-Force Approach Grouping with xsl:variable
» Summary Sorting and Grouping Elements
» Recursive design An Aside: Doing Math with Recursion
» Generating output to initialize a variable
» Overview Invoking the document Function
» The document Function and Sorting
» Implementing Lookup Tables More Sophisticated Techniques
» Grouping Across Multiple Documents
» Summary Combining XML Documents
» Example: Generating multiple output files
» Example: Using extension functions from multiple processors
» Example: A library of trigonometric functions
» Example: Writing extensions in other languages
» Fallback Processing Extension Elements, Extension Functions, and Fallback Processing
» Extending the Saxon Processor
» Generating JPEG Files from XML Content
» About the Toot-O-Matic Case Study: The Toot-O-Matic
» Make It Easier to Create Tutorials
» Individual Panels Tutorial Layout
» Email Panel Zip File PDF Files
» Individual Panels XML Document Design
» Stylesheets and Modes XSLT Source Code
» Initializing Global Variables XSLT Source Code
» Generating the Main Menu Panel
» Generating the Section Indexes
» Generating the Individual Panels
Show more