This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
strange problem with string-replace
- To: xsl-list at mulberrytech dot com
- Subject: strange problem with string-replace
- From: Frederic Schwebel <schwebel at handy dot univ-lyon1 dot fr>
- Date: Thu, 10 Feb 2000 10:22:45 +0100 (MET)
- Reply-To: xsl-list at mulberrytech dot com
Hi,
I'm trying to change MathML into ASCII Braille with XSLT. In Braille, a
mathematical expression has no space and no Line Feed. So I put the string
in a param name and use the "string-replace" template gracefully sent to
me by the Guru David Carlisle. And I get a really strange and annoying
result : when I aks "string-replace" to remove all x or y or ì or any
other printable character, it works perfectly. But when I wand to remove
all (line feed) or   (space) I have a
java.lang.StackOverFlowError, both with xt and saxon (win32 executables)
!!! My stylesheet is small, and I have 64 Mb RAM, so stack shouldn't be a
problem... And even if it was, why would there be a problem only with
spaces and line feeds ? Do these chars have a special characteristic I
don't know ?
My stylesheet and a MathML example are attached.
Thanks a lot, because I really wonder what's wrong...
Frederic
<?xml version='1.0' encoding="ISO-8859-1" ?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY bra1 "â">
<!ENTITY bra2 "ê">
<!ENTITY bra3 "î">
<!ENTITY bra4 "ô">
<!ENTITY bra5 "û">
<!ENTITY bra6 "ë">
<!ENTITY bra7 "ï">
<!ENTITY bra8 "ü">
<!ENTITY bra9 "æ">
<!ENTITY bra0 "¿">
<!ENTITY racine "@">
<!ENTITY fin ";">
<!ENTITY return " ">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method="text" encoding="ISO-8859-1" indent="no"/>
<xsl:variable name="from">&return;</xsl:variable>
<!-- *******************************************
Procedure qui enleve les espaces et les line feed
******************************************* -->
<xsl:template name="string-replace" >
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string,$from)">
<xsl:value-of select="substring-before($string,$from)"/>
<xsl:call-template name="string-replace">
<xsl:with-param name="string" select="substring-after($string,$from)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- *******************************************
On commence au tag Math et on ignore le reste
******************************************* -->
<xsl:template match="*|@*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="math">
<xsl:param name="equation">
<xsl:text>'</xsl:text>
<xsl:apply-templates/>
</xsl:param>
<xsl:call-template name="string-replace">
<xsl:with-param name="string" select="$equation"/>
</xsl:call-template>
<xsl:value-of select="$equation"/>
</xsl:template>
<xsl:template match="mi|mtext|ms">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
<xsl:template match="mrow|none|mspace|semantics">
<xsl:apply-templates/>
</xsl:template>
<!-- *******************************************
Traduction des chiffres et des signes
******************************************* -->
<xsl:template match="mn">
<xsl:value-of select="translate(.,'1234567890','&bra1;&bra2;&bra3;&bra4;&bra5;&bra6;&bra7;&bra8;&bra9;&bra0;')" />
</xsl:template>
<xsl:template match="mo">
<xsl:value-of select="translate(.,'+-/*','!-/(')" />
</xsl:template>
<!-- *******************************************
Racines
******************************************* -->
<xsl:template match="msqrt">
<xsl:text>&racine;</xsl:text>
<xsl:apply-templates/>
<xsl:text>&fin;</xsl:text>
</xsl:template>
<!-- *******************************************
Fractions
******************************************* -->
<xsl:template match="mfrac">
<xsl:apply-templates select="child::*[1]"/>/
<xsl:apply-templates select="child::*[2]"/>
</xsl:template>
<!-- *******************************************
Exposants et indices
******************************************* -->
<xsl:template match="msup">
<xsl:apply-templates select="child::*[1]"/>^
<xsl:apply-templates select="child::*[2]"/>&fin;
</xsl:template>
</xsl:stylesheet>
<math>
<mrow>
<msqrt>
<mrow>
<mfrac>
<mrow>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo><mn>3</mn>
</mrow>
<mrow>
<mn>4</mn><mi>x</mi>
</mrow>
</mfrac>
</mrow>
</msqrt>
</mrow>
</math>