]> matita.cs.unibo.it Git - helm.git/blob - helm/on-line/xslt/utils.xsl
ocaml 3.09 transition
[helm.git] / helm / on-line / xslt / utils.xsl
1 <?xml version="1.0"?>
2
3 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4
5 <!-- Next function to quote strings for JavaScript (i.e. ' ==> \' -->
6 <xsl:template name="jsquote">
7  <xsl:param name="s" select="''"/>
8  <xsl:param name="news" select="''"/>
9  <xsl:param name="times" select="1"/>
10  <xsl:choose>
11   <xsl:when test="$s = ''"><xsl:value-of select="$news"/></xsl:when>
12   <xsl:otherwise>
13    <xsl:variable name="char" select="substring($s,1,1)"/>
14    <xsl:choose>
15     <xsl:when test='$char = "&apos;" and $times = 1'>
16      <xsl:call-template name="jsquote">
17       <xsl:with-param name="s" select="substring($s,2)"/>
18       <xsl:with-param name="news" select='concat($news,"\&apos;")'/>
19       <xsl:with-param name="times" select="$times"/>
20      </xsl:call-template>
21     </xsl:when>
22     <xsl:when test='$char = "&apos;" and $times = 2'>
23      <xsl:call-template name="jsquote">
24       <xsl:with-param name="s" select="substring($s,2)"/>
25       <xsl:with-param name="news" select='concat($news,"\\\&apos;")'/>
26       <xsl:with-param name="times" select="$times"/>
27      </xsl:call-template>
28     </xsl:when>
29     <xsl:otherwise>
30      <xsl:call-template name="jsquote">
31       <xsl:with-param name="s" select="substring($s,2)"/>
32       <xsl:with-param name="news" select="concat($news,$char)"/>
33       <xsl:with-param name="times" select="$times"/>
34      </xsl:call-template>
35     </xsl:otherwise>
36    </xsl:choose>
37   </xsl:otherwise>
38  </xsl:choose>
39 </xsl:template>
40
41 </xsl:stylesheet>