472,119 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

empty quotes != not(string(.)) ????

I have a when statement:

<xsl:when test="//pageTitle[../linkID = $activeLink] = not(string(.))">

This should find the 'pageTitle' node that has a sibling of 'linkID' that
matches the '$activeLink' parameter and see if it is empty or not.

The above returns FALSE

However, this:

<xsl:when test="//pageTitle[../linkID = $activeLink] = ''">

returns TRUE (that's a pair of empty single quotes after the '=')

Why? I thought not(string(.)) *is* the same as an empty element?

-Darrel
Nov 12 '05 #1
8 3641
darrel wrote:

Why? I thought not(string(.)) *is* the same as an empty element?


not(string(.)) returns boolean. So in effect you are comparing node with
boolean? And . in
//pageTitle[../linkID = $activeLink] = not(string(.))
has nothing to do with pageTitle node, instead it refers to current node
in a context xsl:when is executed.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
Hello, darrel!
You wrote on Mon, 12 Apr 2004 15:11:11 -0500:

d> <xsl:when test="//pageTitle[../linkID = $activeLink] =
d> not(string(.))">

d> This should find the 'pageTitle' node that has a sibling of 'linkID'
d> that matches the '$activeLink' parameter and see if it is empty or not.

d> The above returns FALSE

Here is you compare nodeset and boolean value. The comparision is true "if
the result of performing the comparison on the boolean and on the result of
converting the node-set to a boolean using the boolean function is true."

boolean(nodeset) returns true if nodeset is not empty.

So, if the string(context node) is equal to nonempty string, then
not(string(.)) will always return false.
The pageTitle[../linkID = $activeLink] returns non empty nodeset, and above
expression returns false, 'cause true = false equals false.

d> However, this:

d> <xsl:when test="//pageTitle[../linkID = $activeLink] = ''">

d> returns TRUE (that's a pair of empty single quotes after the '=')

d> Why? I thought not(string(.)) *is* the same as an empty element?
Here is you compare nodeset with a string, which is true "if there is a node
in the node-set such that the result of performing the comparison on the
string-value of the node and the other string is true."

Seemingly, there is pageTitle[../linkID = $activeLink] with the empty string
in the document.

With best regards, Alex Shirshov.
Nov 12 '05 #3
not(string(.)) returns boolean. So in effect you are comparing node with
boolean?
Aha! OK...that makes sense now.
//pageTitle[../linkID = $activeLink] = not(string(.))
has nothing to do with pageTitle node, instead it refers to current node
in a context xsl:when is executed.


Not quite sure what that means. Can you elaborate?

I'm still trying to grasp all of the syntax.

I'm trying to find the specific 'pageTitle' element that has a sibling
element of 'linkID' with an empty value. I think the problem is that I'm
looking at a nodeset, not an element?

-Darrel
Nov 12 '05 #4
> Seemingly, there is pageTitle[../linkID = $activeLink] with the empty
string
in the document.


Thanks, Alex.

So, what is the proper way to test for what I'm looking for? Is it fine to
compare a specific node to empty quotes to determine if it is empty?

And is my syntax correct to begin with?

<xsl:when test="//pageTitle[../linkID = $activeLink] = ''">

In english, I'm trying to find the one (well, first, I suppose, though there
is only one) 'pageTitle' element in the document that has a sibling element
'linkID' equal to activeLink. Once found, I want to see if the 'pageTitle'
element is empty.

-Darrel
Nov 12 '05 #5
Hello, darrel!
You wrote on Tue, 13 Apr 2004 09:08:47 -0500:
[Sorry, skipped]

d> In english, I'm trying to find the one (well, first, I suppose, though
d> there is only one) 'pageTitle' element in the document that has a
d> sibling element 'linkID' equal to activeLink. Once found, I want to see
d> if the 'pageTitle' element is empty.

<xsl:if test="string(pageTitle[../linkID = $activeLink]) = ''"></xsl:if>

With best regards, Alex Shirshov.
Nov 12 '05 #6
<xsl:if test="string(pageTitle[../linkID = $activeLink]) = ''"></xsl:if>


Hmm, I had this:

<xsl:when test="//pageTitle[../linkID = $activeLink] = ''">

And then tried your equation:

<xsl:when test="string(pageTitle[../linkID = $activeLink]) = ''">

The first one seems to work, but the second one doesn't. I'm guessing it's
because the second one isn't defining a specific node?

-Darrel
Nov 12 '05 #7
darrel wrote:
//pageTitle[../linkID = $activeLink] = not(string(.))
has nothing to do with pageTitle node, instead it refers to current node
in a context xsl:when is executed.

Not quite sure what that means. Can you elaborate?


In expression
//pageTitle[../linkID = $activeLink] = not(string(.))

<xsl:template match="foo">
<!-- Here current node (context node) is foo -->
<xsl:if test="//pageTitle[../linkID = $activeLink] = not(string(.))">

.. in your expression is foo element.
I'm trying to find the specific 'pageTitle' element that has a sibling
element of 'linkID' with an empty value. I think the problem is that I'm
looking at a nodeset, not an element?


It's
//pageTitle[../linkID = $activeLink][.='']

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #8
Hello, darrel!
You wrote on Tue, 13 Apr 2004 13:47:24 -0500:
??>> <xsl:if test="string(pageTitle[../linkID = $activeLink]) =
??>> ''"></xsl:if>

d> Hmm, I had this:

d> <xsl:when test="//pageTitle[../linkID = $activeLink] = ''">

This will be true if there is a node in nodeset, that reterned by
//pageTitle[../linkID = $activeLink] expression, equals to empty string.

d> And then tried your equation:

d> <xsl:when test="string(pageTitle[../linkID = $activeLink]) = ''">

True if the first node in nodeset, that reterned by //pageTitle[../linkID =
$activeLink] expression, equals to empty string.

I use string function, 'cause you said
[q]
I'm trying to find the _one_ (well, _first_, I suppose, though there is only
one)
[/q]

d> The first one seems to work, but the second one doesn't. I'm guessing
d> it's because the second one isn't defining a specific node?

Please, be more precise and post some snippets of the original xml.

With best regards, Alex Shirshov.
Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Wayno | last post: by
3 posts views Thread by tornado | last post: by
4 posts views Thread by Cyrus D. | last post: by
14 posts views Thread by cj | last post: by
3 posts views Thread by Bob | last post: by
31 posts views Thread by noagbodjivictor | last post: by
4 posts views Thread by MartinRinehart | last post: by

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.