How can I strip line breaks from my XML with XSLT?

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2010-06-05T07:48:53Z Indexed on 2010/06/05 7:52 UTC
Read the original article Hit count: 181

Filed under:
|
|

I have this XSLT:

<xsl:strip-space elements="*" />
<xsl:template match="math">
    <img class="math">
        <xsl:attribute name="src">http://latex.codecogs.com/gif.latex?<xsl:value-of
            select="text()" /></xsl:attribute>
    </img>
</xsl:template>

Which is being applied to this XML (notice the line break):

<math>\text{average} = \alpha \times \text{data} + (1-\alpha) \times
    \text{average}</math>

Unfortunately, the transform creates this:

<img
    class="math"
    src="http://latex.codecogs.com/gif.latex?\text{average} = \alpha \times \text{data} + (1-\alpha) \times&#10;&#9;&#9;&#9;&#9;&#9;\text{average}" />

Notice the whitespace character literals. Although it works, it's awfully messy. How can I prevent this?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt