XProc steps

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

p:label-elements

<p:declare-step type="p:label-elements">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="attribute" select="'xml:id'"/> <!-- QName -->
   <p:option name="attribute-prefix"/> <!-- NCName -->
   <p:option name="attribute-namespace"/> <!-- anyURI -->
   <p:option name="label" select="'concat("_",$p:index)'"/><!-- XPathExpression -->
   <p:option name="match" select="'*'"/> <!-- XSLTMatchPattern -->
   <p:option name="replace" select="'true'"/> <!-- boolean -->
</p:declare-step>

The <p:label-elements> step generates a label and adds it to the appropriate elements as an attribute. The available options give the user the possibility to configure the label. The “attribute“ option expects as input type a QName which will be the later display name of the attribute.
The options “attribute-prefix“ and “attribute-namespace“ give the user the possibility to assign a namespace and a prefix to the attribute. “label“ and “match“ are used for positioning and for the content of the label. “match“ expects a XSLT expression which informs the processor at which position in the document the label shall be placed. Whereas the “label“ option expects a XPath expression which generates the content of the label. If “replace“ is set to “true“, an already existing label will be overwritten with the new one.

Example

In the known input document (“FilmCollection.xml“) a label with the content of the film title shall be generated. The example is very trivial and shall only demonstrate the functionality of the feature.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
   <p:input port="source">
      <p:document href="FilmCollection.xml"/>
   </p:input>
   <p:output port="result"/>
   <p:label-elements attribute="Title" match="/FilmCollection/Film/Title" label="text()"/>
</p:declare-step>

The result of this stylesheet would be as follows (excerpt):

[...]   
  <Title Title="Star Wars: Episode IV - A New Hope">Star Wars: Episode IV - A New Hope</Title>
[...]      
  <Title Title="Eraserhead">Eraserhead</Title>
[...]
  <Title Title="Unforgiven">Unforgiven</Title>
[...]