Hello!
I've come across a strange error that occurs, when you try to return a
nodelist from a variable with a choose/where/otherwise statement.
I'm not quite sure whether it's a bug or simply lack of W3C support. All I
know is, that this Xsl document works with the current implementation of
MSXML V4.0 SP2 if transformed using e.g. VB6. I'm told by the compiler at
runtime, that "the expression should evaluate to a nodeset" (the
choose/where/otherwise part).
What this Xsl document basically does is to look for the parameter
"ImageID". If the ImageID is empty, the first image in the Xml file is
selected. Alternately, the Image matching the parameter "ImageID" is
selected.
The strange part is, that the processor is perfectly capably of computing a
string value in a variable using a choose/where/otherwise part, but not a
nodelist (obviously). I've included the part that fails, as well as the
complete Xsl/Xml listing.
The error is generated only if you reference the beforementioned variable in
the Xsl (e.g. trying to reference an attribute)
This works:
<xsl:variable name="oImage" select="$oImageList[@ImageID = $ImageID]"/>
But this doesn't:
<xsl:variable name="oImage">
<xsl:choose>
<xsl:when test="$ImageID = ''">
<xsl:value-of select="$oImageList[position() = 1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$oImageList[@ImageID = $ImageID]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
-- o --
ImageList.xsl (complete):
<?xml version="1.0" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no"/>
<xsl:param name="ImageID"/>
<xsl:variable name="oImageList" select="/ImageList/Image"/>
<xsl:variable name="oImage">
<xsl:choose>
<xsl:when test="$ImageID = ''">
<xsl:value-of select="$oImageList[position() = 1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$oImageList[@ImageID = $ImageID]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template match="/">
ImageID is: <xsl:value-of select="$oImage/@ImageID"/>
</xsl:template>
</xsl:stylesheet>
ImageList.xml (short excempt - some elements removed):
<ImageList>
<Image ImageID="1"/>
<Image ImageID="2"/>
<Image ImageID="3"/>
<Image ImageID="4"/>
<Image ImageID="5"/>
</ImageList>
Thanks in advance!
--
venlig hilsen / with regards
anders borum
--