- <xsl:template name="string-replace">
- <xsl:param name="subject"/>
- <xsl:param name="search"/>
- <xsl:param name="replace"/>
- <xsl:choose>
- <xsl:when test="contains($subject, $search)">
- <xsl:variable name="before" select="substring-before($subject, $search)"/>
- <xsl:variable name="after" select="substring-after($subject, $search)"/>
- <xsl:value-of select="$before"/>
- <xsl:value-of select="$replace"/>
- <xsl:call-template name="string-replace">
- <xsl:with-param name="subject" select="$after"/>
- <xsl:with-param name="search" select="$search"/>
- <xsl:with-param name="replace" select="$replace"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$subject"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
+<xsl:template name="escape">
+ <xsl:param name="subject"/> <!-- required -->
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject">
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject">
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject" select="$subject"/>
+ <xsl:with-param name="search" select="'\'"/>
+ <xsl:with-param name="replace" select="'\\'"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ <xsl:with-param name="search" select="'"'"/>
+ <xsl:with-param name="replace" select="'\"'"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ <xsl:with-param name="search" select="' '"/>
+ <xsl:with-param name="replace" select="'\n'"/>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="string-replace">
+ <xsl:param name="subject"/>
+ <xsl:param name="search"/>
+ <xsl:param name="replace"/>
+ <xsl:choose>
+ <xsl:when test="contains($subject, $search)">
+ <xsl:variable name="before" select="substring-before($subject, $search)"/>
+ <xsl:variable name="after" select="substring-after($subject, $search)"/>
+ <xsl:value-of select="$before"/>
+ <xsl:value-of select="$replace"/>
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject" select="$after"/>
+ <xsl:with-param name="search" select="$search"/>
+ <xsl:with-param name="replace" select="$replace"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$subject"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>