473,465 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditionally assigning nodesets to a variable

Hello!

I need to a assign a node(-set) conditionally to a varialbe like:

<xsl:variable name="foo">
<xsl:if test="$bar=''">
<!-- how can I access a node here ?-->
</xsl:if>
<xsl:if test="not($bar='')">
<!-- how can I access a node here ?-->
</xsl:if>
</xsl:variable>

but how can I do it? I would need a <xsl:select> tag, which does not exist.

I would be gratefull for any suggestions.

Greetings,

Hans

Jul 20 '05 #1
2 3070

you use any xslt that returns a value for example
<xsl:varibale name-"foo">
<xsl:if test="$bar=''">
<xsl:value-of select="/foo/bar">
</xsl:if>

or

<xsl:if test="$bar=''">
<xsl:apply-templates select="/foo/bar/x">
</xsl:if>

etc

if you only need to use the result of the apply templates as a string/number
etc then you access it using <xsl:value-of select="$foo"/>

but if it returns a node-set (e.g. foo/bar/x) then you must use a processor
specifc extension e.g.

<xsl:for-each select="msxsl:node-set($foo/bar/x)">

and declare a namespace dfor the extension

Colin
"Hans-Michael Rupp" <ha*******@danet.de> wrote in message
news:3F**************@danet.de...
Hello!

I need to a assign a node(-set) conditionally to a varialbe like:

<xsl:variable name="foo">
<xsl:if test="$bar=''">
<!-- how can I access a node here ?-->
</xsl:if>
<xsl:if test="not($bar='')">
<!-- how can I access a node here ?-->
</xsl:if>
</xsl:variable>

but how can I do it? I would need a <xsl:select> tag, which does not exist.
I would be gratefull for any suggestions.

Greetings,

Hans

Jul 20 '05 #2
Hi Hans,

If you need the variable to contain references to the original nodes (rather
than copies of the original nodes placed into a result tree fragment) then
you can usually accomplish this using XPath predicates. For example, taking
your original code and modifying it a little...

<xsl:variable name="foo">
<xsl:if test="$bar=''">
<xsl:copy-of select="//a"/>
</xsl:if>
<xsl:if test="not($bar='')">
<xsl:copy-of select="//b"/>
</xsl:if>
</xsl:variable>

then using XPath predicates you could do...
<xsl:variable name="foo" select="//a[$bar=''] | //b[not($bar='')]"/>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Hans-Michael Rupp" <ha*******@danet.de> wrote in message
news:3F**************@danet.de...
Hello!

I need to a assign a node(-set) conditionally to a varialbe like:

<xsl:variable name="foo">
<xsl:if test="$bar=''">
<!-- how can I access a node here ?-->
</xsl:if>
<xsl:if test="not($bar='')">
<!-- how can I access a node here ?-->
</xsl:if>
</xsl:variable>

but how can I do it? I would need a <xsl:select> tag, which does not exist.
I would be gratefull for any suggestions.

Greetings,

Hans

Jul 20 '05 #3

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

Similar topics

5
by: gtz669 | last post by:
I have a class which I am using for data stroage. I declare an instance of that class in my main class which is running my java applet. I Iassign it a value in the init () function and it works...
0
by: vanGogh | last post by:
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool. My goal is to: - write an application that can parse XML documents - fill objects (based on the generated...
6
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and...
6
by: Arthur | last post by:
I had two Visual Studio .NET C++ solutions that I combined into one. These project solutions were very similar. In fact, the two solutions were sharing many files. Now that they are one...
3
by: | last post by:
One thing I did a lot of in Classic ASP involved showing page elements conditionally based on whether a user was logged in or not. Logged in users or "superusers" would get more content and/or more...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
25
by: Sourav | last post by:
Suppose I have a code like this, #include <stdio.h> int *p; void foo(int); int main(void){ foo(3); printf("%p %d\n",p,*p);
15
by: d4 | last post by:
I have a vbscript (below) I want to rewrite in C# but I cannot get it to work (unless there is a better way to do it). The script will combine 2 lines if the (next) line contains a "+",...
3
by: yasmin | last post by:
I am trying to conditionally compile macros in my c++ program. I want to simply be able to use the macro name without enclosing it in #ifdef-#endif each time. How can I enclose the macro definition...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.