XML technologies / XSLT / Reference: XSLT 1.0 & 2.0 elements / non-matching-substring
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 6.)
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
The instruction xsl:non-matching-substring When processing a sequence generated by xsl:analyze-string, this processes the substrings of the input that do not match the comparison pattern.
Classification | Sub-instruction |
Functional group | Testing string values |
Introduction | XSLT 2.0 |
Position in the stylesheet and permitted content:
The sub-instruction xsl:non-matching-substring occurs as the second child element within the template body of xsl:analyze-string.
The element contains a sequence constructor to process the supplied substring from the sequence generated by xsl:analyze-string. The template body may contain text, arbitrary literal result elements and XSLT instructions.
Attributes:
Only the standard attributes apply. xsl:non-matching-substring has no element-specific attributes.
Purpose:
The instruction xsl:non-matching-substring processes the input substrings for which the regular expression of xsl:analyze-string does not find a match (match). The instruction is called for each substring in the order determined by its occurrence in the output sequence of xsl:analyze-string. There may be at most one sub-instruction xsl:non-matching-substring in xsl:analyze-string, preceded by at most one sub-instruction xsl:matching-substring and followed by any number of xsl:fallback elements.
The end tag </xsl:non-matching-substring> must always be present. An abbreviated form is not permitted, even with an empty template body. (In that case, however, the element may be omitted entirely from the content of xsl:analyze-string.)
Since the lexical form of a non-matching substring is usually unpredictable, it is generally either discarded, through an empty or omitted xsl:non-matching-substring instruction, or passed on unchanged.
Example – using xsl:non-matching-substring:
Source document:
<?xml version="1.0" encoding="UTF-8"?>
<beispiel>Fischsuppe enthält Fisch.</beispiel>
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<ergebnis>
<xsl:analyze-string select="beispiel" regex="Fisch">
<xsl:matching-substring><em>Karotten</em></xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</ergebnis>
</xsl:template>
</xsl:stylesheet>
The matching substring is replaced and surrounded by <em> tags; the non-matching substring is passed through unchanged using xsl:value-of.
Result:
<?xml version="1.0" encoding="UTF-8"?>
<ergebnis>
<em>Karotten</em>suppe enthält <em>Karotten</em>.
</ergebnis>
Element definition:
XSLT 1.0:
Element not available in XSLT 1.0.
XSLT 2.0:
<!-- Category: sub-instruction -->
<xsl:non-matching-substring>
<!-- keine Attribute -->
<!-- Content: sequence-constructor -->
</xsl:non-matching-substring>
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn