Chapter 2XML inclusions

The general form of an XML inclusion is:

  |<xi:include xmlns:xi='http://www.w3.org/2001/XInclude'
  |            href='/path/to/document.xml'
  |            parse='xml'
  |            fragid='xpointer(…)'/>

The parse attribute is optional in this case. The fragment identifier is also optional; if it’s not present, the entire document is included. The attribute xpointer can be used instead of fragid.

For the purposes of the examples that follow, let’s imagine a small XML document, abstraction.xml, one that I could include in its entirety with XInclude:

  |<blockquote xmlns="http://docbook.org/ns/docbook" version="5.2">
  |<title>Abstraction</title>
  |<attribution><personname>Paul Hudak</personname></attribution>
  |<para xml:id="abs"><quote>Abstraction, abstraction and abstraction.</quote>
  |This is the answer to the question, <quote>What are the three most
  |important words in programming?</quote></para>
  |</blockquote>

Like so:

Example 2.1XML inclusion without a fragment identifier
  |<xi:include href="abstraction.xml"/>
Subexample 2.1.1The XInclude
Abstraction

Abstraction, abstraction and abstraction. This is the answer to the question, What are the three most important words in programming?

Paul Hudak
Subexample 2.1.2What’s included

2.1XML fragment identifier schemes

The XML fragment identifier schemes are spelled out in the XPointer Framework.

SInclude supports:

id(some-id) and its shorthand syntax

The id scheme identifies an XML element by its ID. The shorthand syntax for this common case is simply the value of the ID, some-id.

Example 2.2XML inclusion with fragment identifier
  |<xi:include href="abstraction.xml" fragid="abs"/>
Subexample 2.2.1The XInclude

Abstraction, abstraction and abstraction. This is the answer to the question, What are the three most important words in programming?

Subexample 2.2.2What’s included
element(some-id/1/3)

The element scheme identifies an XML element with an optional ID followed by a child sequence. The child sequence is just the numbers of the children (i.e., the third child of the first child is /1/3).

Example 2.3XML inclusion with fragment identifier and child sequence
  |<xi:include href="abstraction.xml" fragid="abs/2"/>
Subexample 2.3.1The XInclude
What are the three most important words in programming?
Subexample 2.3.2What’s included
xmlns(binding)

The xmlns scheme doesn’t identify anything directly, but it provides a namespace binding for the XPointer parts that follow it, as shown in the xpath example below.

xpath(expression)

The xpath scheme identifies content with XPath. The SInclude implementation makes no attempt to limit the expressions to XPath 1 or 2 or any other version. It simply asks Saxon to evaluate the expression.

Example 2.4XML inclusion with fragment identifier and child sequence
  |<!-- Use xmlns() to set the namespace binding for the following expression -->
  |<xi:include href="abstraction.xml"
  |            fragid="xmlns(db=http://docbook.org/ns/docbook)
  |                    xpath(/db:blockquote/db:attribution/db:personname)"/>
Subexample 2.4.1The XInclude
Paul Hudak
Subexample 2.4.2What’s included