]> granicus.if.org Git - docbook-dsssl/commitdiff
Fix bug #496453: make sure comments don't contain illegal chars
authorNorman Walsh <ndw@nwalsh.com>
Sun, 9 Jun 2002 11:43:04 +0000 (11:43 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Sun, 9 Jun 2002 11:43:04 +0000 (11:43 +0000)
xsl/fo/index.xsl
xsl/lib/lib.xweb

index c2ca705e9786e4cac6716277cb6cfbda2861ef91..cf588e2eac4649bab65207224867c953a3a1f979 100644 (file)
       <xsl:call-template name="object.id"/>
     </xsl:attribute>
     <xsl:comment>
-      <xsl:value-of select="primary"/>
-      <xsl:if test="secondary">
-        <xsl:text>, </xsl:text>
-        <xsl:value-of select="secondary"/>
-      </xsl:if>
-      <xsl:if test="tertiary">
-        <xsl:text>, </xsl:text>
-        <xsl:value-of select="tertiary"/>
-      </xsl:if>
+      <xsl:call-template name="comment-escape-string">
+        <xsl:with-param name="string">
+          <xsl:value-of select="primary"/>
+          <xsl:if test="secondary">
+            <xsl:text>, </xsl:text>
+            <xsl:value-of select="secondary"/>
+          </xsl:if>
+          <xsl:if test="tertiary">
+            <xsl:text>, </xsl:text>
+            <xsl:value-of select="tertiary"/>
+          </xsl:if>
+        </xsl:with-param>
+      </xsl:call-template>
     </xsl:comment>
   </fo:wrapper>
 </xsl:template>
index d51255d1c1bc4821894b0670a958abaade366b81..3be848c493e2b611d26110ce91fdd44df250834c 100644 (file)
@@ -554,6 +554,73 @@ absolute path from the root of the tree to the current element node.
 </refsect1>
 </refentry>
 
+<!-- ================================================================== -->
+
+<refentry id="comment-escape-string">
+<refnamediv>
+<refname>comment-escape-string</refname>
+<refpurpose>Prepare a string for inclusion in an XML comment</refpurpose>
+</refnamediv>
+
+<refsect1><title>Description</title>
+
+<para>The <function>comment-escape-string</function> template returns a string
+that has been transformed so that it can safely be output as an XML comment.
+Internal occurrences of "--" will be replaced with "- -" and a leading and/or
+trailing space will be added to the string, if necessary.</para>
+
+<programlisting><src:fragment id='comment-escape-string'>
+<xsl:template name="comment-escape-string">
+  <xsl:param name="string" select="''"/>
+
+  <xsl:if test="starts-with($string, '-')">
+    <xsl:text> </xsl:text>
+  </xsl:if>
+
+  <xsl:call-template name="comment-escape-string.recursive">
+    <xsl:with-param name="string" select="$string"/>
+  </xsl:call-template>
+
+  <xsl:if test="substring($string, string-length($string), 1) = '-'">
+    <xsl:text> </xsl:text>
+  </xsl:if>
+</xsl:template>
+</src:fragment></programlisting>
+
+</refsect1>
+</refentry>
+
+<refentry id="comment-escape-string.recursive">
+<refnamediv>
+<refname>comment-escape-string.recursive</refname>
+<refpurpose>Internal function used by comment-escape-string</refpurpose>
+</refnamediv>
+
+<refsect1><title>Description</title>
+
+<para>The <function>comment-escape-string.recursive</function> template is used
+by <function>comment-escape-string</function>.</para>
+
+<programlisting><src:fragment id="comment-escape-string.recursive">
+<xsl:template name="comment-escape-string.recursive">
+  <xsl:param name="string" select="''"/>
+  <xsl:choose>
+    <xsl:when test="contains($string, '--')">
+      <xsl:value-of select="substring-before($string, '--')"/>
+      <xsl:value-of select="'- -'"/>
+      <xsl:call-template name="comment-escape-string.recursive">
+        <xsl:with-param name="string" select="substring-after($string, '--')"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$string"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+</src:fragment></programlisting>
+</refsect1>
+</refentry>
+
 </reference>
 
 <reference>
@@ -690,6 +757,8 @@ around these functions.</para>
 <src:fragref linkend="pi-attribute.frag"/>
 <src:fragref linkend="lookup.key.frag"/>
 <src:fragref linkend="xpath.location.frag"/>
+<src:fragref linkend="comment-escape-string"/>
+<src:fragref linkend="comment-escape-string.recursive"/>
 <src:fragref linkend="count.uri.path.depth.frag"/>
 <src:fragref linkend="trim.common.uri.paths.frag"/>