[xslt] str:replace conformance

I wonder if str:replace conforms to its specification.
The style sheet fragment below is intended to replace a set of
characters in the current text node with a set of longer
strings representing the escaped TeX version of those
characters. Consider the text:

 (#) ($) (%) ({) (}) (_) (\)

The intended transformation is to produce this:

 (\#) (\$) (\%) (\{) (\}) (\_) ($\backslash$)

when the Jeni Tennison XSLT version of str:replace is used
(see stylesheet fragment at end), the result is this:

 (<to>\#</to>) (<to>\$</to>) [... etc.]

which, when the output mode is "text", produces the desired
result. I would have thought the *contents" of the corresponding
replacement nodes would be inserted, but in fact the spec
does seem to say "the equivalently positioned node", for
better or worse.

However, the libexslt version of str:replace produces this:

($\backslash$#) ($\backslash$$) ($\backslash$%) [... etc.]

So, maybe there are two problems. First, if the entire corresponding
replacement node is supposed to be inserted, then I think libexslt
is not doing it. Second, it seems like libexslt's str:replace is
willing to alter text it has already altered (first, "#" was replaced
with "\#", then further replacements applied to that). One
could argue that the spec is not 100% unambiguous on this
point (though it was explicitly forbidden in discussion
behind the spec, AFAICT). However, if this point is
ambiguous, that would render str:replace useless for a large
class of its applications, given that one could't really guess
what result would appear from one implementation to another.

The stylesheet fragment in question is this:

<xsl:output method="text" />


<xsl:template match="text()">
   <xsl:variable name="Replace">

<!-- to call the Jeni Tennison version
    <xsl:call-template name="str:replace">
        <xsl:with-param name="string" select="."/>
<xsl:with-param name="search" select="exsl:node-set($Replace)/FromXml/from"/> <xsl:with-param name="replace" select="exsl:node-set($Replace)/ToTex/to"/>
<xsl:value-of select="str:replace(.,exsl:node-set($Replace)/FromXml/from,exsl:node-set($Replace)/ToTex/to)" </xsl:template>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]