Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > 6e019a662639ac6470f50dea3a4d8157 > files > 954

docbook-style-xsl-doc-1.79.2-4.mga7.noarch.rpm

<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>trim.text</title><link rel="stylesheet" type="text/css" href="../reference.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.2"><link rel="home" href="../index.html" title="DocBook XSL Stylesheets: Reference&nbsp;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>&nbsp;</td><th width="60%" align="center">General Library Templates</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="str.tokenize.keep.delimiters.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="trim.text"></a><div class="titlepage"></div><div class="refnamediv"><h2>trim.text</h2><p>trim.text &#8212; Trim leading and trailing whitespace from a text node</p></div><div class="refsect1"><a name="d0e33477"></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">

  &lt;xsl:template name="trim.text"&gt;
    &lt;xsl:param name="contents" select="."&gt;&lt;/xsl:param&gt;
    &lt;xsl:variable name="contents-left-trimmed"&gt;
      &lt;xsl:call-template name="trim-left"&gt;
        &lt;xsl:with-param name="contents" select="$contents"&gt;&lt;/xsl:with-param&gt;
      &lt;/xsl:call-template&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:variable name="contents-trimmed"&gt;
      &lt;xsl:call-template name="trim-right"&gt;
        &lt;xsl:with-param name="contents" select="$contents-left-trimmed"&gt;&lt;/xsl:with-param&gt;
      &lt;/xsl:call-template&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:value-of select="$contents-trimmed"&gt;&lt;/xsl:value-of&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template name="trim-left"&gt;
    &lt;xsl:param name="contents"&gt;&lt;/xsl:param&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test="starts-with($contents,'
') or                       starts-with($contents,'') or                       starts-with($contents,' ') or                       starts-with($contents,'	')"&gt;
        &lt;xsl:call-template name="trim-left"&gt;
          &lt;xsl:with-param name="contents" select="substring($contents, 2)"&gt;&lt;/xsl:with-param&gt;
        &lt;/xsl:call-template&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select="$contents"&gt;&lt;/xsl:value-of&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template name="trim-right"&gt;
    &lt;xsl:param name="contents"&gt;&lt;/xsl:param&gt;
    &lt;xsl:variable name="last-char"&gt;
      &lt;xsl:value-of select="substring($contents, string-length($contents), 1)"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test="($last-char = '
') or                       ($last-char = '') or                       ($last-char = ' ') or                       ($last-char = '	')"&gt;
        &lt;xsl:call-template name="trim-right"&gt;
          &lt;xsl:with-param name="contents" select="substring($contents, 1, string-length($contents) - 1)"&gt;&lt;/xsl:with-param&gt;
        &lt;/xsl:call-template&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select="$contents"&gt;&lt;/xsl:value-of&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
</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>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="generallibrary.html">Up</a></td><td width="40%" align="right">&nbsp;<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&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;str.tokenize.keep.delimiters</td></tr></table></div></body></html>