This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Passing thru numerical character ref


Warren Hedley writes:

> The following might work.
>
> <xsl:text
disable-output-escaping="yes"><![CDATA[&#x3b0;&#x3bb;&#x3b7;]]></xsl:text>

It works only if you need to insert a piece of text within a stylesheet.
But when the text to be quoted resides *in the XML source*, the stylesheet
cannot control the output. Instead, one can redefine the default rule for
#PCDATA elements:

<xsl:template match="text()">
  <xsl:value-of disable-output-escaping="yes" select="."/>
</xsl:template>

It is really dangerous, as you cannot write things like &amp; in your code any
more - instead, you should put it as &amp;amp; or <![CDATA[&amp;]]>. To limit
the damage, I would suggest wrapping all Greek text into a special element -
say, <greek-quote> - and applying the redefined template to its data children
only: match="greek-quote/text()".

As a radical workaround, one can look for a specific character and replace it
with a quoted sequence:

<xsl:template match="greek-quote/text()">
  <xsl:call-template name="replace-char">
    <xsl:with-param name="string-to-quote" select="."/>
    <xsl:with-param name="char" select="'&#x3b0;'"/>
    <xsl:with-param name="replacement" select="'&amp;#x3b0;'"/>
  </xsl:call-template>
</xsl:template>

<!-- This template replaces all occurrences of a certain substring -->
<!-- by another substring, and disables output escaping for the -->
<!-- newly substituted part. -->

<xsl:template name="replace-char">
  <xsl:param name="string-to-quote"/>
  <xsl:param name="char"/>
  <xsl:param name="replacement"/>

  <xsl:choose>
    <xsl:when test="contains($string-to-quote, $char)">
      <xsl:value-of select="substring-before($string-to-quote, $char)"/>
      <xsl:value-of disable-output-escaping="yes" select="$replacement"/>
      <xsl:call-template name="replace-char">
        <xsl:with-param name="string-to-quote"
             select="substring-after($string-to-quote, $char)"/>
        <xsl:with-param name="char" select="$char"/>
        <xsl:with-param name="replacement" select="$replacement"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise><xsl:value-of select="$string-to-quote"/></xsl:otherwise>
  </xsl:choose>
</xsl:template>

This is a really dirty hack - a replacement template should be run for every
character you need to quote! Efficiency drawbacks are evident, but... it lets
you write normal XML sources. When Xalan bug is fixed, you just throw away this
chunk, and you're back to normality ;-).

Regards,
Nikolai Grigoriev





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]