Add explicit xml:base attributes to a document.
<p:declare-step type="p:add-xml-base"> <input port="source" primary="true" content-types="xml html" sequence="false"/> <output port="result" primary="true" content-types="xml html" sequence="false"/> <option name="all" as="xs:boolean" required="false" select="false()"/> <option name="relative" as="xs:boolean" required="false" select="true()"/> </p:declare-step>
The p:add-xml-base
step adds explicit xml:base
attributes to the source document. An xml:base
attribute annotates an
element with a “base URI” value, which is usually the URI this element came from.
Ports:
Type | Port | Primary? | Content types | Seq? | Description |
---|---|---|---|---|---|
|
|
|
|
| The document to add the |
|
|
|
|
| The resulting document. |
Options:
Nodes (elements, attributes, etc.) in XML documents “remember” where they came from: they have a so-called “base
URI” attached. This is usually the URI this node came from: the path (for instance on disk) to the document where it belonged to. In most
cases the base URI is invisible. The p:add-xml-base
step exposes this by adding (or adapting) xml:base
attributes.
The operation of the p:add-xml-base
step depends on the values of the all
and relative
options:
all | relative | Operation |
---|---|---|
|
|
|
|
| These are the default values for these options.
|
|
|
|
|
| This is not allowed. Error |
The following example shows what happens if we use p:add-xml-base
straight out of the box:
Assume the following source document called in1.xml
:
<texts> <text>Hello XProc lovers…</text> </texts>
Pipeline document:
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0"> <p:input port="source"/> <p:output port="result"/> <p:add-xml-base/> </p:declare-step>
Result document:
<texts xml:base="file:/…/…/in1.xml"> <text>Hello XProc lovers…</text> </texts>
We can create an xml:base
attribute on every element by setting the all
option to
true
. Because the default value for the relative
option is true
and both options can’t both
be true
, we have to set the relative
option to false
explicitly.
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0"> <p:input port="source"/> <p:output port="result"/> <p:add-xml-base all="true" relative="false"/> </p:declare-step>
Result document:
<texts xml:base="file:/…/…/in1.xml"> <text xml:base="file:/…/…/in1.xml">Hello XProc lovers…</text> </texts>
The following example shows what happens if you combine two documents. For this, we’re going to use another XML document called
in2.xml
:
<specialtext>Are you in for something special?</specialtext>
The following pipeline first creates a combined document by inserting this into the same source document we used in the previous example Straight step usage:
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0"> <p:input port="source"/> <p:output port="result"/> <p:insert match="/*" position="last-child"> <p:with-input port="insertion" href="in2.xml"/> </p:insert> <p:add-xml-base/> </p:declare-step>
The result document has a relative xml:base
value on the inserted document because the default value for the
relative
option is true
:
<texts xml:base="file:/…/…/in1.xml"> <text>Hello XProc lovers…</text> <specialtext xml:base="in2.xml">Are you in for something special?</specialtext> </texts>
But we could also ask for absolute base URI values:
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0"> <p:input port="source"/> <p:output port="result"/> <p:insert match="/*" position="last-child"> <p:with-input port="insertion" href="in2.xml"/> </p:insert> <p:add-xml-base relative="false"/> </p:declare-step>
Result document:
<texts xml:base="file:/…/…/in1.xml"> <text>Hello XProc lovers…</text> <specialtext xml:base="file:/…/…/in2.xml">Are you in for something special?</specialtext> </texts>
p:add-xml-base
preserves all document-properties of the document(s) appearing on its source
port.
The xml
namespace prefix as used here is bound to the namespace http://www.w3.org/XML/1998/namespace
. In most
cases you don’t have to bind this prefix explicitly (by adding
xmlns:xml="http://www.w3.org/XML/1998/namespace"
). This namespace binding is part of the XML language.
A formal definition of base URIs and xml:base
attributes can be found here.
Error code | Description |
---|---|
It is a dynamic error if the |
This description of the p:add-xml-base
step is for XProc version: 3.1. This is a required step (an XProc 3.1 processor must support this).
The formal specification for the p:add-xml-base
step can be found here.
The p:add-xml-base
step is part of categories:
The p:add-xml-base
step is also present in version:
3.0.