<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>apply-string-subst-map</title><link rel="stylesheet" type="text/css" href="../reference.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.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="str.tokenize.keep.delimiters.html" title="str.tokenize.keep.delimiters"><link rel="next" href="relativeuri.html" title="Relative URI Functions"><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">apply-string-subst-map</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="str.tokenize.keep.delimiters.html">Prev</a> </td><th width="60%" align="center">General Library Templates</th><td width="20%" align="right"> <a accesskey="n" href="relativeuri.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="apply-string-subst-map"></a><div class="titlepage"></div> <div class="refnamediv"><h2>apply-string-subst-map</h2><p> apply-string-subst-map — Apply a string-substitution map </p></div> <div class="refsect1"><a name="idp9596000"></a><h2>Description</h2> <p>This function applies a “string substitution” map. Use it when you want to do multiple string substitutions on the same target content. It reads in two things: <em class="parameter"><code>content</code></em>, the content on which to perform the substitution, and <em class="parameter"><code>map.contents</code></em>, a node set of elements (the names of the elements don't matter), with each element having the following attributes: </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> <code class="sgmltag-attribute">oldstring</code>, a string to be replaced </li><li class="listitem"> <code class="sgmltag-attribute">newstring</code>, a string with which to replace <code class="sgmltag-attribute">oldstring</code> </li></ul></div><p> The function uses <em class="parameter"><code>map.contents</code></em> to do substitution on <em class="parameter"><code>content</code></em>, and then returns the modified contents.</p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3> <p>This function is a very slightly modified version of Jeni Tennison’s <code class="function">replace_strings</code> function in the <a class="ulink" href="http://www.dpawson.co.uk/xsl/sect2/StringReplace.html#d9351e13" target="_top">multiple string replacements</a> section of Dave Pawson’s <a class="ulink" href="http://www.dpawson.co.uk/xsl/index.html" target="_top">XSLT FAQ</a>.</p> <p>The <code class="function">apply-string-subst-map</code> function is essentially the same function as the <code class="function">apply-character-map</code> function; the only difference is that in the map that <code class="function">apply-string-subst-map</code> expects, <code class="sgmltag-attribute">oldstring</code> and <code class="sgmltag-attribute">newstring</code> attributes are used instead of <code class="sgmltag-attribute">character</code> and <code class="sgmltag-attribute">string</code> attributes.</p> </div> <a name="apply-string-subst-map.frag"></a><pre class="programlisting"> <xsl:template name="apply-string-subst-map"> <xsl:param name="content"></xsl:param> <xsl:param name="map.contents"></xsl:param> <xsl:variable name="replaced_text"> <xsl:call-template name="string.subst"> <xsl:with-param name="string" select="$content"></xsl:with-param> <xsl:with-param name="target" select="$map.contents[1]/@oldstring"></xsl:with-param> <xsl:with-param name="replacement" select="$map.contents[1]/@newstring"></xsl:with-param> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="$map.contents[2]"> <xsl:call-template name="apply-string-subst-map"> <xsl:with-param name="content" select="$replaced_text"></xsl:with-param> <xsl:with-param name="map.contents" select="$map.contents[position() > 1]"></xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$replaced_text"></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="str.tokenize.keep.delimiters.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="relativeuri.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">str.tokenize.keep.delimiters </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Relative URI Functions</td></tr></table></div></body></html>