str:replace questions
Ron Burk <[email protected]> Tue, 27 Jan 2009 10:18:48 -0800
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <[email protected]> |
I'm looking at three things:
a) the str:replace specification
http://www.exslt.org/str/functions/replace/str.replace.html
b) an exslt.org XSLT template implementation
http://www.exslt.org/str/functions/replace/str.replace.template.xsl
c) the libexslt implementation used via xsltproc
My first question is: does the spec really mean to say that
the replacement value is "the equivalently positioned node"
instead of "the contents of the equivalently positioned node"?
The exslt.org template seems to agree that it is the former,
whereas it looks to me like libexslt implements the latter.
My second question is a statement :-): it would be helpful
if the spec were explicit about forbidding replacement operations
from affecting previous replacements. This is another behavior
on which exslt.org and libexslt seem to differ.
Finally, assuming the exslt.org implementation is correct,
I'm having trouble figuring out how to do simple string
replacements using the exslt.org implementation. Using
replacement nodes of "<to>xxx</to>" will insert unwanted
elements in the output, rather than just the replacement
strings. Using replacement text nodes seems not to work;
even though I pass str:replace 9 text nodes, it seems to
treat them as a single replacement string formed by
concatenating all of them together. I cannot see the
error of my ways.
An example fragment follows:
<xsl:template match="text()">
<xsl:variable name="Replace">
<FromXml>
<from>#</from>
<from>$</from>
<from>%</from>
<from>_</from>
<from>{</from>
<from>}</from>
<from>~</from>
<from>^</from>
<from>\</from>
</FromXml>
<ToTex>
<to>\#</to>
<to>\$</to>
<to>\%</to>
<to>\_</to>
<to>\{</to>
<to>\}</to>
<to>\~{}</to>
<to>\^{}</to>
<to>$\backslash$</to>
</ToTex>
</xsl:variable>
<!-- puts unwanted 'to' elements in output -->
<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:call-template>
<!-- acts as though I passed it a single replacement string -->
<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/text()"/>
</xsl:call-template>
</xsl:template>