]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/on-line/xslt/utils.xsl
There were still many problems with URIs with a ' in the middle.
[helm.git] / helm / on-line / xslt / utils.xsl
diff --git a/helm/on-line/xslt/utils.xsl b/helm/on-line/xslt/utils.xsl
new file mode 100644 (file)
index 0000000..9213c24
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<!-- Next function to quote strings for JavaScript (i.e. ' ==> \' -->
+<xsl:template name="jsquote">
+ <xsl:param name="s" select="''"/>
+ <xsl:param name="news" select="''"/>
+ <xsl:param name="times" select="1"/>
+ <xsl:choose>
+  <xsl:when test="$s = ''"><xsl:value-of select="$news"/></xsl:when>
+  <xsl:otherwise>
+   <xsl:variable name="char" select="substring($s,1,1)"/>
+   <xsl:choose>
+    <xsl:when test='$char = "&apos;" and $times = 1'>
+     <xsl:call-template name="jsquote">
+      <xsl:with-param name="s" select="substring($s,2)"/>
+      <xsl:with-param name="news" select='concat($news,"\&apos;")'/>
+      <xsl:with-param name="times" select="$times"/>
+     </xsl:call-template>
+    </xsl:when>
+    <xsl:when test='$char = "&apos;" and $times = 2'>
+     <xsl:call-template name="jsquote">
+      <xsl:with-param name="s" select="substring($s,2)"/>
+      <xsl:with-param name="news" select='concat($news,"\\\&apos;")'/>
+      <xsl:with-param name="times" select="$times"/>
+     </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+     <xsl:call-template name="jsquote">
+      <xsl:with-param name="s" select="substring($s,2)"/>
+      <xsl:with-param name="news" select="concat($news,$char)"/>
+      <xsl:with-param name="times" select="$times"/>
+     </xsl:call-template>
+    </xsl:otherwise>
+   </xsl:choose>
+  </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>