Daniel Israel
05-31-2007, 07:09 PM
I'm working on a project to define opinion polls. I have an XSLT document that lists the polls and some data about them and when they click on it, it displays the data for the clicked on poll (works great). They can edit, etc.
Where I am having a problem is that I want to be able to create a NEW poll with the same form. So when I click NEW, it sets the current poll ID to 0 (zero). The problem is (besides me being a noob at XSLT ;) ) there's no node to get the data from. So what I've done is this:
1. Create a template to display the data.
2. Define a "default" variable that has the empty data for a new poll
3. If I have an ID of zero, I just pass the "default" data to the template.
The XSLT looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:variable name="qid">0</xsl:variable>
<xsl:variable name="filter" select="Polls/Poll[ID=$qid]"></xsl:variable>
<xsl:variable name="NewPoll">
<Poll>
<ID>NEW</ID>
<Question></Question>
<StartDate></StartDate>
<EndDate></EndDate>
<Status></Status>
<Answers>
</Answers>
</Poll>
</xsl:variable>
<xsl:template name="Display">
<xsl:param name="poll"/>
<!-- Cut here... This displays the form properly and seems to work... -->
</xsl:template>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$qid=0">
<xsl:call-template name="Display">
<xsl:with-param name="poll" select="$NewPoll"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Display">
<xsl:with-param name="poll" select="Polls/Poll[ID=$qid]"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Now, when I click on an existing one, it works fine, but when I click for a new one, I get the following error from firefox:
Error during XSLT transformation: An XPath expression was expected to return a NodeSet.
Any help/pointers is appreciated. Thanks!
Where I am having a problem is that I want to be able to create a NEW poll with the same form. So when I click NEW, it sets the current poll ID to 0 (zero). The problem is (besides me being a noob at XSLT ;) ) there's no node to get the data from. So what I've done is this:
1. Create a template to display the data.
2. Define a "default" variable that has the empty data for a new poll
3. If I have an ID of zero, I just pass the "default" data to the template.
The XSLT looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:variable name="qid">0</xsl:variable>
<xsl:variable name="filter" select="Polls/Poll[ID=$qid]"></xsl:variable>
<xsl:variable name="NewPoll">
<Poll>
<ID>NEW</ID>
<Question></Question>
<StartDate></StartDate>
<EndDate></EndDate>
<Status></Status>
<Answers>
</Answers>
</Poll>
</xsl:variable>
<xsl:template name="Display">
<xsl:param name="poll"/>
<!-- Cut here... This displays the form properly and seems to work... -->
</xsl:template>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$qid=0">
<xsl:call-template name="Display">
<xsl:with-param name="poll" select="$NewPoll"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Display">
<xsl:with-param name="poll" select="Polls/Poll[ID=$qid]"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Now, when I click on an existing one, it works fine, but when I click for a new one, I get the following error from firefox:
Error during XSLT transformation: An XPath expression was expected to return a NodeSet.
Any help/pointers is appreciated. Thanks!