473,659 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xsl variable $node/text() but $node can non-node-set help!

I have a variable $value as a parameter in the following template:

<xsl:template name="myTemplat e">
<xsl:param name="value"/>
<xsl:if test="$value">
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:template>

Now i call myTemplate sometimes whit the a parameter $value that
is sometimes a text node, and sometimes it is not even a node.
Example:

<inputDoc>
<a>hello</a>
<a/>
</inputDoc>

xsl:

<xsl:for-each select="/inputDoc/a">
<xsl:call-template name="myTemplat e">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>
</xsl:for-each>
So i call myTemplate with parameter $value=a/text()

But for the second <aelement in <inputDocther e
is not text() node.

This gives me the following error:

Cause: javax.xml.trans form.Transforme rException: The value is not a
node-set

With line number of the error pointing to the xsl:if in myTemplate.
No i tried the function nilled(), but that is XPath 2.0, i only
use XPath 1.0 and XSL 1.0

i know a possible solution is this:

<xsl:for-each select="/inputDoc/a">
<xsl:choose>
<xsl:when test=".[not(node())]">

<xsl:call-template name="myTemplat e">
<xsl:with-param name="value" select="false() "/>
</xsl:call-template>

</xsl:when>
<xsl:otherwis e>

<xsl:call-template name="myTemplat e">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>

</xsl:otherwise>
</xsl:for-each>
But this requires me to change every call to myTemplate,
which is alot of code. Can't i change myTemplate so
it works?

Who can help me? Please..
Aug 23 '06 #1
2 5447


Tjerk Wolterink wrote:
I have a variable $value as a parameter in the following template:

<xsl:template name="myTemplat e">
<xsl:param name="value"/>
<xsl:if test="$value">
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:template>

Now i call myTemplate sometimes whit the a parameter $value that
is sometimes a text node, and sometimes it is not even a node.
Example:

<inputDoc>
<a>hello</a>
<a/>
</inputDoc>

xsl:

<xsl:for-each select="/inputDoc/a">
<xsl:call-template name="myTemplat e">
<xsl:with-param name="value" select="./text()"/>
That means the value you pass in _is_ a node set (of text nodes) but
that node set might be empty. I don't see why that should give you an
error for <xsl:if test="$value">, doing that test on an empty node set
should simply yield false.
This gives me the following error:

Cause: javax.xml.trans form.Transforme rException: The value is not a
node-set

With line number of the error pointing to the xsl:if in myTemplate.
What XSLT processor is that? Are you sure the code is as simple as you
have posted? Have you tried with different XSLT processors?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 23 '06 #2
There is nothing wrong with the posted code -- either the reason is in code
that was not shown or the XSLT processor used is non-compliant.

A typical advise/requirement is to post a complete (but the minimal
possible) example of the xslt stylesheet and the source xml document, to say
what is the expected result, what is the actual result and how the actual
result differs from what was expected.

Cheers,
Dimitre Novatchev.
"Tjerk Wolterink" <tj***@wolterin kwebdesign.comw rote in message
news:ec******** **@netlx020.civ .utwente.nl...
>I have a variable $value as a parameter in the following template:

<xsl:template name="myTemplat e">
<xsl:param name="value"/>
<xsl:if test="$value">
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:template>

Now i call myTemplate sometimes whit the a parameter $value that
is sometimes a text node, and sometimes it is not even a node.
Example:

<inputDoc>
<a>hello</a>
<a/>
</inputDoc>

xsl:

<xsl:for-each select="/inputDoc/a">
<xsl:call-template name="myTemplat e">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>
</xsl:for-each>
So i call myTemplate with parameter $value=a/text()

But for the second <aelement in <inputDocther e
is not text() node.

This gives me the following error:

Cause: javax.xml.trans form.Transforme rException: The value is not a
node-set

With line number of the error pointing to the xsl:if in myTemplate.
No i tried the function nilled(), but that is XPath 2.0, i only
use XPath 1.0 and XSL 1.0

i know a possible solution is this:

<xsl:for-each select="/inputDoc/a">
<xsl:choose>
<xsl:when test=".[not(node())]">

<xsl:call-template name="myTemplat e">
<xsl:with-param name="value" select="false() "/>
</xsl:call-template>

</xsl:when>
<xsl:otherwis e>

<xsl:call-template name="myTemplat e">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>

</xsl:otherwise>
</xsl:for-each>
But this requires me to change every call to myTemplate,
which is alot of code. Can't i change myTemplate so
it works?

Who can help me? Please..

Aug 24 '06 #3

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

Similar topics

6
6738
by: Hansan | last post by:
Hi all. I am working on a webpage where I use python and html. When I want to send one variable to a new script/page I use the following code: 0) print '''<input type=hidden name="eventid" value='''+str(variable_name)+'''>''' This works fine, the problem occurs when I want to send a variable to a page
8
2208
by: 2L | last post by:
Trying to write some code and this is just shitting me now! Bit of form validation stuff.... Variable is declared as follows..... --snip-- <script language="JavaScript"> <!---
3
1801
by: ziemon | last post by:
// index.html <a href="test.html?menu=menu1">menu1</a> <a href="test.html?menu=menu1_1">menu1_1</a> // index.html // test.html
1
1536
by: Morgan Cheng | last post by:
Hi, This isssue consfuse me. According to <Thinking in C++>, temporay variable is *const*. like class X{}; X f(){return X();} void g1(X&){} void g2(const X&){}
15
12114
by: Lauren Wilson | last post by:
Access 2K dim MyStr as string What is the maximum amount of text or bytes that this variable can store? Does anyone know?
10
2763
by: Ni | last post by:
I found out smth strange in g++ >= 3.3.5 => I was able to do register char buff;//// where outSTDBuffer is a variable!!!! Is it a bug in gcc or specification of c++ changed?? I've noticed this a mistake after successfull compilation of my program! Should I change the code. I think `register char buff;` is much safer then use pointers in case if outSTDBuffer is small!!!
3
1981
by: James Robertson | last post by:
I am new to the ASP and VB thing so be kind. Question I have is that I have created an ASPX web site to use as an E-Mail page. But I want to use this for a lot of users. Can I create the link on the WEB site to mail to passing a variable from the WEB site to the ASPX web site to E-Mail to? Hope I explained this correctly. This is a response from another group. There was no way for you to know it, but this is a classic asp newsgroup....
19
3097
by: Manish Tomar | last post by:
Hi All, The following code as per my knowledge should not work: int* some() { int b = 10; return &b; }
112
5425
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
1
1999
by: JavaJon | last post by:
The problem in the follow code occurs when trying to instantiate an array object. public class Main { /** * @param args the command line arguments */ public static void main(String args) { Room rooms;
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8525
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,...
0
7356
agi2029
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...
1
6179
isladogs
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...
0
4175
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...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
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 we have to send another system

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.