blob: ee1dc069de04a1f8bef9c2f6cb01a0583ff84025 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>trim.text</title><link rel="stylesheet" type="text/css" href="../reference.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.1"><link rel="home" href="../index.html" title="DocBook XSL Stylesheets: Reference Documentation"><link rel="up" href="generallibrary.html" title="General Library Templates"><link rel="prev" href="comment-escape-string.recursive.html" title="comment-escape-string.recursive"><link rel="next" href="str.tokenize.keep.delimiters.html" title="str.tokenize.keep.delimiters"><link rel="copyright" href="copyright.html" title="License"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">trim.text</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="comment-escape-string.recursive.html">Prev</a> </td><th width="60%" align="center">General Library Templates</th><td width="20%" align="right"> <a accesskey="n" href="str.tokenize.keep.delimiters.html">Next</a></td></tr></table><hr></div><div class="refentry" title="trim.text"><a name="trim.text"></a><div class="titlepage"></div>
<div class="refnamediv"><h2>trim.text</h2><p>
trim.text
— Trim leading and trailing whitespace from a text node
</p></div>
<div class="refsect1" title="Description"><a name="id36258595"></a><h2>Description</h2>
<p>Given a text node, this function trims leading and trailing
whitespace from it and returns the trimmed contents.</p>
<a name="trim.text.frag"></a><pre class="programlisting">
<xsl:template name="trim.text">
<xsl:param name="contents" select="."></xsl:param>
<xsl:variable name="contents-left-trimmed">
<xsl:call-template name="trim-left">
<xsl:with-param name="contents" select="$contents"></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="contents-trimmed">
<xsl:call-template name="trim-right">
<xsl:with-param name="contents" select="$contents-left-trimmed"></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$contents-trimmed"></xsl:value-of>
</xsl:template>
<xsl:template name="trim-left">
<xsl:param name="contents"></xsl:param>
<xsl:choose>
<xsl:when test="starts-with($contents,'
') or starts-with($contents,'
') or starts-with($contents,' ') or starts-with($contents,' ')">
<xsl:call-template name="trim-left">
<xsl:with-param name="contents" select="substring($contents, 2)"></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$contents"></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="trim-right">
<xsl:param name="contents"></xsl:param>
<xsl:variable name="last-char">
<xsl:value-of select="substring($contents, string-length($contents), 1)"></xsl:value-of>
</xsl:variable>
<xsl:choose>
<xsl:when test="($last-char = '
') or ($last-char = '
') or ($last-char = ' ') or ($last-char = ' ')">
<xsl:call-template name="trim-right">
<xsl:with-param name="contents" select="substring($contents, 1, string-length($contents) - 1)"></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$contents"></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</pre>
</div>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="comment-escape-string.recursive.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="generallibrary.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="str.tokenize.keep.delimiters.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">comment-escape-string.recursive </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> str.tokenize.keep.delimiters</td></tr></table></div></body></html>
|