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="$oImage List[@ImageID = $ImageID]"/>
But this doesn't:
<xsl:variable name="oImage">
<xsl:choose>
<xsl:when test="$ImageID = ''">
<xsl:value-of select="$oImage List[position() = 1]"/>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="$oImage List[@ImageID = $ImageID]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
-- o --
ImageList.xsl (complete):
<?xml version="1.0" ?>
<xsl:styleshe et
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="oImageLis t" select="/ImageList/Image"/>
<xsl:variable name="oImage">
<xsl:choose>
<xsl:when test="$ImageID = ''">
<xsl:value-of select="$oImage List[position() = 1]"/>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="$oImage List[@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
-- 3 2023
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="$oImage List[position() = 1]"/>
Should be
<xsl:copy-of select="$oImage List[1]"/> </xsl:when> <xsl:otherwis e> <xsl:value-of select="$oImage List[@ImageID = $ImageID]"/>
Should be
<xsl:copy-of select="$oImage List[@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="$oImage List[1][$ImageID=''] | $oImageList[@ImageID = $ImageID]"/>
--
Oleg Tkachenko http://www.tkachenko.com/blog
Multiconn Technologies, Israel
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="$oImage List[1][$ImageID=''] | $oImageList[@ImageID =
$ImageID]"/>
Which unfortunately is not what I had in mind (although it probably works).
--
venlig hilsen / with regards
anders borum
--
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
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 extension responsible
for the xslt functions. The problem i have is that the obtained
transformation is not the waited one. I try to proccess the same XML
file with XSL file with a program called XMLspy and i obtained the
desire and waited...
|
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, I got it working, but the
OWL-file is formatted differently and I don't know how to access the
elements. I'll post the .owl file below, but this is basically what I want
to get from the file (the course name):
<Course...
|
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 Books.XML and other is Books.XSL, please
refer it
|
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>
<Directory>Root</Directory>
<Dir>true</Dir>
|
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.
The solution i got today is very slow, and i need help to find another
solution.
Here is the xml file. It consists of a list of position ids (ESTOXX50
INDEX_BM_E and FTSE INDEX_BM_E), and below that a list of tags for each
position id. What i...
| |
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 string will often not produce a direct match,
the results will be based on proximity (50%, 20% 100%, etc).
are there any good examples out there on how to do keyword
searches on XML data? How should i set up my xml file so
|
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 elements
(children of log) in my XML source have a time-stamp attribute, so I
want to use the time-stamp from the page for the page-time-stamp
value. I use an xsl:choose/xsl:when/xsl:otherwise combination to setup
an if/else statement to select the...
|
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 language="javascript" type="text/javascript">
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |