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]

strange problem with string-replace



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  "&#226;">

  <!ENTITY bra2  "&#234;">

  <!ENTITY bra3  "&#238;">

  <!ENTITY bra4  "&#244;">

  <!ENTITY bra5  "&#251;">

  <!ENTITY bra6  "&#235;">

  <!ENTITY bra7  "&#239;">

  <!ENTITY bra8  "&#252;">

  <!ENTITY bra9  "&#230;">

  <!ENTITY bra0  "&#191;">

  <!ENTITY racine  "&#64;">

  <!ENTITY fin  "&#59;">

  <!ENTITY return "&#13;">

]>





<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>




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