Name
p:add-xml-base — The standard p:add-xml-base step.
Synopsis
The p:add-xml-base step exposes the base URI via
explicit xml:base attributes. The input document from the
source port is replicated to the result port
with xml:base attributes added to or corrected on each element as specified
by the options on this step.
| Input port | Primary | Sequence | Content types |
|---|---|---|---|
| source | ✔ | xml html |
| Output port | Primary | Sequence | Content types |
|---|---|---|---|
| result | ✔ | xml html |
| Option name | Type | Default value |
|---|---|---|
| all | xs:boolean | false() |
| relative | xs:boolean | true() |
Declaration
1 |<p:declare-step xmlns:p="http://www.w3.org/ns/xproc">
| <p:input port="source" content-types="xml html"/>
| <p:output port="result" content-types="xml html"/>
| <p:option name="all" as="xs:boolean" select="false()"/>
5 | <p:option name="relative" as="xs:boolean" select="true()"/>
|</p:declare-step>Errors
| Code | Description |
|---|---|
err:XC0058 | It is a dynamic error (err:XC0058)
if the all and relative options are
both true. |
Description
The p:add-xml-base step is a
standard XProc 3.0 step.
It is also described on XProcRef.org.
Examples
The following pipeline constructs a document with a base URI of
file:///path/to/examples/. The resulting document is inserted into
a wrapper, once just as it was constructed, and once after
running it through p:add-xml-base.
With the wrapper, the base URI of the example element is
preserved in both cases. If you resolved a URI against the
base URI of either element, it would be resolved against
file:///path/to/examples/.
1 |<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
| version="3.0">
|
| <p:output port="result"/>
5 |
| <p:identity name="example">
| <p:with-input>
| <p:inline document-properties="map {
| 'base-uri': 'file:///path/to/examples/' }">
10 | <example/>
| </p:inline>
| </p:with-input>
| </p:identity>
|
15 | <p:add-xml-base name="fixup"/>
|
| <p:insert position="first-child" match="/wrapper/without-fixup">
| <p:with-input port="source">
| <wrapper xml:base="http://example.com/">
20 | <without-fixup/>
| <with-add-xml-base/>
| </wrapper>
| </p:with-input>
| <p:with-input port="insertion" pipe="@example"/>
25 | </p:insert>
|
| <p:insert position="first-child" match="/wrapper/with-add-xml-base">
| <p:with-input port="insertion" pipe="@fixup"/>
| </p:insert>
30 |</p:declare-step>However, in the serialized the result, the base URI of the first
example isn’t preserved. XML serialization does nothing to preserve
base URIs.
|<wrapper xml:base="http://example.com/">
| <without-fixup><example/></without-fixup>
| <with-add-xml-base><example xml:base="file:///path/to/examples/"/></with-add-xml-base>
| </wrapper>The
p:add-xml-base step makes each element’s base URI explicit using
XML Base. Consequently,
the base URI of the second example has been recorded in
an explicit xml:base attribute.
If the serialized document is re-parsed, the base URI of the second
example will still be correct, while the base URI of the first
has been lost.
Adding xml:base attributes to your document may
have other consequences, for example in validation. The xml:base
attribute is an attribute like any other, it must be declared in your schema and it will
be visible to other processes.