Jump to content

XSLT Processing Error

Guest FirefoxRocks

Recommended Posts

Guest FirefoxRocks

In Opera, I get this error:

XSLT processing failed!
In Firefox, I get this error:
Error loading stylesheet: XPath parse failure: operator expected:
I have no clue what those mean but here is my XSLT style sheet:
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <html> <head><title><xsl:value-of select="//site/name"/> Development Status</title><style type="text/css">/*<![CDATA[*/html{background-color:blue}h1{text-align:center}body{background-color:gold;color:blue}/*]]>*/</style></head> <body> <h1><xsl:value-of select="//site/name"/> Development Status</h1> <p>Developer: <xsl:value-of select="//developer"/></p> <p>Site URL: <xsl:value-of select="//site/url"/><br />Beta URL: <xsl:value-of select="//site/beta"/></p> <xsl:for-each select="//project">	<xsl:choose>        <xsl:when test="//primary=Not started">            <div style="background-color:red">        </xsl:when>        <xsl:when test="//primary=Developing">            <div style="background-color:#fa0">        </xsl:when>		<xsl:when test="//primary=Testing">            <div style="background-color:#ff0">        </xsl:when>		<xsl:when test="//primary=Release Candidate">            <div style="background-color:#aaf">        </xsl:when>		<xsl:when test="//primary=Stable">            <div style="background-color:#0f0">        </xsl:when>		<xsl:otherwise>			<div style="background-color:#fff">		</xsl:otherwise>	</xsl:choose>	<h2>Project: <xsl:value-of select="name"/></h2>	<p>Purpose: <xsl:value-of select="purpose"/></p>	<p>Status: <xsl:value-of select="status/primary"/> - <xsl:value-of select="status/secondary"/></p>	<p>Project time span: <xsl:value-of select="time/span"/> days<br />	Actual time spent on project: <xsl:value-of select="time/actual"/> hours</p>	<p>Notes: <xsl:value-of select="notes"/></p>	</div>	<hr /> </xsl:for-each><p><a href="http://validator.w3.org/check/referer"><img src="http://www.w3.org/Icons/valid-xml10-blue.png" alt="Valid XML 1.0!" height="31" width="88" /></a></p> </body> </html></xsl:template></xsl:stylesheet>

The problem occurred when I added the <xsl:choose> stuff, should I just stick with a whole bunch of <xsl:if> statements instead? How do I fix this?

Link to comment
Share on other sites

The divs in the whens don't have /div closing tags.Also there's an extra /div closing tag here (commented out by me):

<p>Notes: <xsl:value-of select="notes"/></p><!--</div>-->

Lastly your xpath needs quotes around the values you're testing for. You may be getting away with it when there's no space in the value, but it's a good practice to use quotes anyway. These ones are failing:

<xsl:when test="//primary=Not started"><xsl:when test="//primary=Release Candidate">

which need to become:

<xsl:when test="//primary='Not started'"><xsl:when test="//primary='Release Candidate'">

Just out of interest, what do you use for your xsl validation/testing? I don't do a huge amount of xsl, and what I do I do in Visual Studio, and it told me all of the above errors, so you might want to try using that if you happen to have Visual Studio anyway. Not the obvious tool of choice for xsl, but may help.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...