p:delete (3.1) 

Delete nodes in documents.

Summary

<p:declare-step type="p:delete">
  <input port="source" primary="true" content-types="xml html" sequence="false"/>
  <output port="result" primary="true" content-types="text xml html" sequence="false"/>
  <option name="match" as="xs:string" required="true"/>
</p:declare-step>

The p:delete step deletes nodes, specified by an XSLT selection pattern, from the document appearing on its source port.

Ports:

Port

Type

Primary?

Content types

Seq?

Description

source

input

true

xml html

false

The document to delete the nodes from.

result

output

true

text xml html

false

The resulting document.

Options:

Name

Type

Req?

Description

match

xs:string (XSLT selection pattern)

true

The XSLT match pattern for the nodes to delete, as a string.

Description

The p:delete step takes the XSLT match pattern in the match option and holds this against the document appearing on its source port. Any matching nodes are deleted (including child nodes, if any). The resulting document appears on the result port.

Note that deleting an element means that the entire element, including child elements, gets deleted. If you just want to delete the element but keep its child elements, you need p:unwrap.

Examples

Basic usage

The following example deletes all <text> elements with an attribute type="normal" from the source document.

Source document:

<texts>
   <text>Hello there!</text>
   <text>This is funny…</text>
   <text type="normal">And that's normal.</text>
   <text type="normal">Very normal…</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:delete match="text[@type eq 'normal']"/>
  
</p:declare-step>

Result document:

<texts>
   <text>Hello there!</text>
   <text>This is funny…</text>
</texts>

Additional details

  • p:delete preserves all document-properties of the document(s) appearing on its source port.

  • This step cannot remove namespaces, if you try this XC0023 is raised. For removing namespaces use p:namespace-delete.

  • Deleting an xml:base attribute does not change the base URI of the element on which it occurred.

Errors raised

Error code

Description

XC0023

It is a dynamic error if the selection pattern matches a wrong type of node.

XC0062

It is a dynamic error if the match option matches a namespace node.

Reference information

This description of the p:delete 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:delete step can be found here.

The p:delete step is part of categories:

The p:delete step is also present in version: 3.0.