Previous Up Next


p:escape-markup

p:escape-markup — Escapes XML markup.

Synopsis

<p:declare-step type="p:escape-markup">
     <p:input port="source"/>
     <p:output port="result"/>
     <p:option name="cdata-section-elements" select="''"/>         <!-- ListOfQNames -->
     <p:option name="doctype-public"/>                             <!-- string -->
     <p:option name="doctype-system"/>                             <!-- anyURI -->
     <p:option name="escape-uri-attributes" select="'false'"/>     <!-- boolean -->
     <p:option name="include-content-type" select="'true'"/>       <!-- boolean -->
     <p:option name="indent" select="'false'"/>                    <!-- boolean -->
     <p:option name="media-type"/>                                 <!-- string -->
     <p:option name="method" select="'xml'"/>                      <!-- QName -->
     <p:option name="omit-xml-declaration" select="'true'"/>       <!-- boolean -->
     <p:option name="standalone" select="'omit'"/>                 <!-- "true" | "false" | "omit" -->
     <p:option name="undeclare-prefixes"/>                         <!-- boolean -->
     <p:option name="version" select="'1.0'"/>                     <!-- string -->
</p:declare-step>

Description

The p:escape-markup step serializes the children of the document element of its source document and replaces those children with their serialization. The result is a single element with text content that represents the “escaped” syntax of the children as they were serialized.

This step supports most of the standard serialization options; these options control how the output markup is produced before it is escaped. This step produces an XML document that contains the escaped characters of the serialized representation, not an encoded octet stream. The serialization options related to encoding characters (byte-order-mark, encoding, and normalization-form) do not apply and cannot be used on this step.

By default, this step does not generate an XML declaration in the escaped result.

Examples

Some non-XML systems require markup to be escaped. This can be achieved with the p:escape-markup step.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:escape-markup/>
  5 </p:pipeline>
Input Output
1 <document>
<para>This is a paragraph of text.</para>
<para>So is this</para>
</document>
 
1 <document>
&lt;para&gt;This is a paragraph of text.&lt;/para&gt;
&lt;para&gt;So is this&lt;/para&gt;
</document>

Observe that p:escape-markup does not escape the document element of its input. It can't. If it did, the output of the step would not be well-formed XML.

To encode an entire document, place it in a wrapper first. The easiest way to do that is with p:wrap-sequence.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:wrap-sequence wrapper="my-wrapper"/>
  5 
      <p:escape-markup/>
    </p:pipeline>
Input Output
1 <document>
<para>This is a paragraph of text.</para>
<para>So is this</para>
</document>
 
1 <my-wrapper>&lt;document&gt;
&lt;para&gt;This is a paragraph of text.&lt;/para&gt;
&lt;para&gt;So is this&lt;/para&gt;
&lt;/document&gt;</my-wrapper>

Then in subsequent steps, such as p:http-request, you can extract the contents of the wrapper, as necessary.