Xml+XSL: Problems with FireFox displaying

  • Thread starter Jesper Stocholm
  • Start date
J

Jesper Stocholm

I have som XML that link to an XSL-file to enable on-the-fly
HTML-generation by e.g. IE or FireFox. The transformation actually works
like a charm, but I have problems with changing line breaks in the XML to
their html-equivilant <br/>.

I use the XSL:

<xsl:template name="break">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '
')">
<xsl:value-of select="substring-before($text, '
')"/>
<br/>
<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$text"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

And I apply it to the specific XML-element with the code

<xsl:call-template name="break">
<xsl:with-param name="text" select="description"/>
</xsl:call-template>

When I display the XML-file in IE, it all looks fine and dandy - but when I
load the page in FireFox (1.0 PR), the linebreaks are not converted to
html-<br>-tags.

What am I doing wrong?

And - are there some programs out there that will allow me to supply a
XML-file and a XSL-stylesheet - and then display the result of the
XSL(T)-transaformation?
 
M

Martin Honnen

Jesper said:
I have som XML that link to an XSL-file to enable on-the-fly
HTML-generation by e.g. IE or FireFox. The transformation actually works
like a charm, but I have problems with changing line breaks in the XML to
their html-equivilant <br/>.

I use the XSL:

<xsl:template name="break">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '
')">
<xsl:value-of select="substring-before($text, '
')"/>
<br/>
<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$text"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

And I apply it to the specific XML-element with the code

<xsl:call-template name="break">
<xsl:with-param name="text" select="description"/>
</xsl:call-template>

When I display the XML-file in IE, it all looks fine and dandy - but when I
load the page in FireFox (1.0 PR), the linebreaks are not converted to
html-<br>-tags.

What am I doing wrong?

Hard to tell, maybe you can post the URLs of a short XML sample and XSLT
demonstrating the problem. I see nothing wrong in that XSLT snippet you
have above but the problem could be with your XML input.
 
J

Jesper Stocholm

Jesper Stocholm wrote:

Hard to tell, maybe you can post the URLs of a short XML sample and XSLT
demonstrating the problem. I see nothing wrong in that XSLT snippet you
have above but the problem could be with your XML input.

the content is located at http://blog.stocholm.dk

When displayed in IE the result is as expected - but not in FireFox

:)
 
M

Martin Honnen

Jesper said:
the content is located at http://blog.stocholm.dk

When displayed in IE the result is as expected - but not in FireFox

You are transforming to XHTML but inside that template you call the
<br/> elements are in the null namespace so make that

<xsl:template name="break">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '
')">

<xsl:value-of select="substring-before($text, '
')"/>
<br xmlns="http://www.w3.org/1999/xhtml" />
<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$text"/>
</xsl:eek:therwise>

</xsl:choose>
</xsl:template>

and it should work.

By the way, to output a DOCTYPE node you shouldn't use disable output
escaping but rather the <xsl:eek:utput> element.
 
J

Jesper Stocholm

You are transforming to XHTML but inside that template you call the
<br/> elements are in the null namespace so make that

aah ... :eek:)

<xsl:template name="break">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '
')">

<xsl:value-of select="substring-before($text, '
')"/>
<br xmlns="http://www.w3.org/1999/xhtml" />
<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$text"/>
</xsl:eek:therwise>

</xsl:choose>
</xsl:template>

and it should work.

It did, thanks.

By the way, to output a DOCTYPE node you shouldn't use disable output
escaping but rather the <xsl:eek:utput> element.

Ok - I see your point. I changed it to

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
encoding="ISO-8859-1"
method="html"
/>

And the above now also looks as intended in FireFox.

Thanks for your help and have a nice weekend,

:eek:)
 
M

Morris M. Keesan

And - are there some programs out there that will allow me to supply a
XML-file and a XSL-stylesheet - and then display the result of the
XSL(T)-transaformation?

If you have a recent version of IE, you probably have MSXML somewhere on
your system, if you can figure out how to use it.

Or you can use either of these two open-source XSLT processors

Saxon: http://saxon.sourceforge.net/ (Java based)
Xalan: http://xml.apache.org/xalan-j/ (Java version)
or http://xml.apache.org/xalan-c/ (C++ version)
 
J

John Fereira

And - are there some programs out there that will allow me to supply a
XML-file and a XSL-stylesheet - and then display the result of the
XSL(T)-transaformation?

If you're looking for something that is free. Try jEdit. I know several
people that like Eclipse and XMLBuddy as well. XMLSpy and StyleStudio are
both good commercial products that will perform XML/XSLT transformation.
The Xalan package has a simple XSTL transformation example that works fine
from a command line.
 
J

Jesper Stocholm

If you have a recent version of IE, you probably have MSXML somewhere on
your system, if you can figure out how to use it.

I bet I can - I have used it before, I just seem to remember a command-line
tool I once used to test xslt-transformation.
Or you can use either of these two open-source XSLT processors

Saxon: http://saxon.sourceforge.net/ (Java based)
Xalan: http://xml.apache.org/xalan-j/ (Java version)

I will look at the above - or write a small test-harness in C#.

Thanks,

:eek:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top