开发者

Why won't Firefox parse this XSLT?

I've recently been playing around with XML formatting and XLST files, because it seems like the most direct solution to a UI problem I've been wrestling with involving users accessing the central data differently. In my experimentation I've created a really nice formatting sheet that looks great... in Internet Explorer. When I test it in Firefox, I consistently get the same error message:

"Error loading stylesheet: Parsing an XSLT stylesheet failed."

I've tried paring the stylesheet down to a very basic document and still experience the same problem. I've been checkin开发者_C百科g tutorials and other webforums and mimic'ing examples, but I can't seem to find anything that is explicitly applicable.

Here's my test XML file:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="fox.xslt"?>
<article>
   <title>Making Excellent Pasta Sauce</title>
   <synopsis>A simple recipe for an amazing sauce, with tips on getting that extra flavor.</synopsis>
   <content>Here is my content.</content>
   <tags>
      <tag>sauce</tag>
      <tag>recipes</tag>
   </tags>
</article>

And then, here's my XSLT file (named, as you might tell from the example block above, "fox.xslt".

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
   <head>
   </head>
   <body>
   <xsl:for-each select="article">
      TITLE: <xsl:value-of select="title"/> <BR/>
      SYNOPSIS: <xsl:value-of select="synopsis"/> <BR/><BR/>
   </xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

I suspect that it may have something to do with <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> because I've seen a few different things done with this in examples, I've tried a few of the different values here and haven't seem to hit on one that works with this example.

I'm sure it's probably a basic problem, I just have been flummoxed at tracking down. Hopefully someone can lead me to the "forehead smacking moment".

Thanks in advance!


Try to replace your stylesheet element with this:

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

You may also want to add this:

xmlns="http://www.w3.org/1999/xhtml"


I find it most useful to use a separate tool to find the problems that FireFox (et al) will not report. Install and use, say, the xsltproc command, which gives much more helpful results.

For example, I encountered a file where Firefox's only response was (take your pick): "Parsing an XSLT stylesheet failed" or, with version=1.1 in the stylesheet, " the equally useless "Parsing an XSLT expression failed."

So, I went to the command-line and entered, say ..."xsltproc bah.xsl humbug.xml" then, presto, there it was:

error
xsltCompileStepPattern : ']' expected
compilation error: file bah.xsl line 157 element template
xsltCompilePattern : failed to compile 'ATOM[@STATE='GAS''

I therefore routinely run all of my XML and XSL files through xsltproc or its equivalent such that they "run clean" before feeding it to my friendly neighborhood browser. I have not yet found any browser that "graciously and informatively" handles an XSLT issue.

In addition, I find it quite-frankly easier to look at the command output (which is HTML), say by piping it to the less or more commands for pagination, than to try looking at it in a browser, until I know that I am very close to what I am looking for. If I'm trying to find a problem in the generated (say) HTML output, I really don't want to look at it "as HTML" at first. If the XSL transforms are "spewing nonsense" (as, of course, they do at first, at least for me), a browser's attempts to turn it into something beautiful just gets in the way of finding the bugs in the stylesheet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜