Previous Up Next


p:unwrap

p:unwrap — Removes an element, but not its content.

Synopsis

<p:declare-step type="p:unwrap">
     <p:input port="source"/>
     <p:output port="result"/>
     <p:option name="match" required="true"/>                      <!-- XSLTMatchPattern -->
</p:declare-step>

Description

The p:unwrap step replaces an element with its content. In other words, it deletes the element wrapper but not the children of the element.

Every element in the input document that matches is replaced by its children, effectively “unwrapping” the children from their parent.

This step produces a single document; if the document element is unwrapped, the result might not be well-formed XML.

Errors

Error Description
err:C0023 Occurs if the match pattern matches anything other than element nodes.

Examples

In this example, we unwrap pre elements from their containing div parents.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:h="http://www.w3.org/1999/xhtml"
                version="1.0">
    
  5   <p:unwrap match="h:div[h:pre]"/>
    </p:pipeline>
Input Output
1 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Some Document</title>
</head>
5 <body>
<div>
<p class="add">This is new text.</p>
<p class="del">Some text.</p>
<div>
10 <pre class="chg">Some pre text.</pre>
</div>
</div>
<div class="del strikeout">
<pre>Some more example pre text.</pre>
15 </div>
</body>
</html>
 
1 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Some Document</title>
</head>
5 <body>
<div>
<p class="add">This is new text.</p>
<p class="del">Some text.</p>
<div>
<pre class="chg">Some pre text.</pre>
10 </div>
</div>
<div class="del strikeout">
<pre>Some more example pre text.</pre>
</div>
</body>
</html>

Compare these results with p:delete.

The p:unwrap step uses a match pattern which can apply at many different depths in the document tree. In particular, note that the unwrapped content is also subject to unwrapping.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:h="http://www.w3.org/1999/xhtml"
                version="1.0">
    
  5   <p:unwrap match="h:div"/>
    </p:pipeline>
Input Output
1 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Some Document</title>
</head>
5 <body>
<div>
<p class="add">This is new text.</p>
<p class="del">Some text.</p>
<div>
10 <pre class="chg">Some pre text.</pre>
</div>
</div>
<div class="del strikeout">
<pre>Some more example pre text.</pre>
15 </div>
</body>
</html>
 
1 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Some Document</title>
</head>
5 <body>
<div>
<p class="add">This is new text.</p>
<p class="del">Some text.</p>
<div>
<pre class="chg">Some pre text.</pre>
</div>
</div>
<div class="del strikeout">
<pre>Some more example pre text.</pre>
</div>
10 </body>
</html>

Using a simple match pattern of div effectively removes every single div from the document.