473,320 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Bug in Xsl Transformation (unable to return nodelist using choose/where/otherwise in variable)

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
--
Nov 11 '05 #1
3 1998
Anders Borum wrote:
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. According to your code you are returning not nodelist, but string value.
But this doesn't:
<xsl:variable name="oImage">
<xsl:choose>
<xsl:when test="$ImageID = ''">
<xsl:value-of select="$oImageList[position() = 1]"/> Should be
<xsl:copy-of select="$oImageList[1]"/> </xsl:when>
<xsl:otherwise>
<xsl:value-of select="$oImageList[@ImageID = $ImageID]"/>


Should be
<xsl:copy-of select="$oImageList[@ImageID = $ImageID]"/>

And once you have a variable that holds result tree fragment (xsl:variable
with content instead of select attribute) you cannot query it by XPath unless
you convert its value to nodeset using msxml:node-set() function.
So try this trick as a workaround:

<xsl:variable name="oImage"
select="$oImageList[1][$ImageID=''] | $oImageList[@ImageID = $ImageID]"/>

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Hello Oleg!

Thanks for the quick reply. I'll give it a try at home later. However,
regarding your comments I don't quite agree that I'm returning a string
(rather than a nodelist as requested). Are you sure the <xsl:copy-of/>
approach works compared to <xsl:value-of/>?

And my secondary concern is why this works with e.g. MSXML 4.0 SP2. I'm only
encountering this issue with the .NET framework.

If the <xsl:copy-of/> approach works, it'll be a no-brainer. I'd just like
to know why Microsoft didn't provide the same behaviour in the .NET
framework.

<xsl:variable name="oImage"
select="$oImageList[1][$ImageID=''] | $oImageList[@ImageID =
$ImageID]"/>

Which unfortunately is not what I had in mind (although it probably works).

--
venlig hilsen / with regards
anders borum
--
Nov 11 '05 #3
Hello Oleg!

I'll check into it later and get back to you!

Again thanks for the discussion so far

--
venlig hilsen / with regards
anders borum
--
Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
4
by: Fredrik Henricsson | last post by:
Hey, I'm building an ontology in Protégé and I want to transform parts of it (e.g. the instances) to HTML with XSL. When I was transforming another file with 'simple' XML-tags like <author> before,...
4
by: Rushi | last post by:
Hi friends, I'm beginner in XSL/XSLT. And i m very impressive, as it is separating presentation and data layer. Now my question is related to XSL transform. Below are sample files one is...
6
by: dave | last post by:
I really have 2 questions regarding the following xml snippet. The xml is a directory representation. <?xml version="1.0" standalone="yes"?> <FileSystem> <Row> <ID>1</ID> <Name>Root</Name>...
1
by: sommarlov | last post by:
Hi everyone >From one of our systems an xml file is produced. I need to validate this file before we send it to an external system for a very lenghty process. I cannot change the xml file layout....
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
2
by: Kevin | last post by:
I am having difficulty updating a variable page-time-stamp in the following snippit. The variable time-stamp is initialized from the attribute time-stamp from the log element. Some of the page...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.