472,371 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XPath expression to test for empty node?

My xml doc has many <title></title> and <title> in it, meaning the
nodes have no content (although some do). How can I test for this?

I tried title[. is null] (doesn't work)
I tried //title[node() is null] (doesn't work)
I tried //title[text() is null] (doesn't work)
I tried //title[text() = ''] (doesn't work)

Any suggestions welcome.

Thank you,
-KJ

Jul 20 '05 #1
4 61381
KJ
I meant (in the 2nd example) <title/>

Jul 20 '05 #2
n_**********@mail.com writes:
My xml doc has many <title></title> and <title> in it, meaning the
nodes have no content (although some do). How can I test for this?
This is a faq you should csee the xsl-list faq at www.dpawson.co.uk

I tried title[. is null] (doesn't work) the is operator is only in XPath2 which is still in draft form
that is legal but always selects an empty sequence as it selects all
title elements that are the same node as their child <null> elements,
which can't happen.
I tried //title[node() is null] (doesn't work) That is again XPath2 only and is the same as //[null] and selects all
title elements that have a child element called null.
I tried //title[text() is null] (doesn't work)
that again is xpath2 only and is the empty sequence, it selects all
title elements which have a text node which is an element node with name
null. text nodes are never element nodes so this selects nothing.
I tried //title[text() = ''] (doesn't work) This one is valid XPath1 but selects nothing as it selects all title
elements that have a text node with value '' but text nodes are never
empty in Xpath, an empty node has no child at all, not a text node with
empty string value.

To test if the current element has no children you just need
test="not(node())"

to match on empty title elements you could do
<xsl:template match="title[not(node())]">
empty title was here
</xsl:template>

Any suggestions welcome.

Thank you,
-KJ

Jul 20 '05 #3


n_**********@mail.com wrote:
My xml doc has many <title></title> and <title> in it, meaning the
nodes have no content (although some do). How can I test for this?

I tried title[. is null] (doesn't work)
I tried //title[node() is null] (doesn't work)
I tried //title[text() is null] (doesn't work)
I tried //title[text() = ''] (doesn't work)


Use
//title[not(text())]
for <title> elements which have no text content.
Or use
//title[not(node())]
for <title> elements which have no child nodes at all (i.e. which are
empty).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
KJ
thank you very much!

Jul 20 '05 #5

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

Similar topics

3
by: ricky | last post by:
I want to return with only one xpath expression the first following node relative to a node with a XPTO attribute. Example: <node> xxx </node> <node XPTO="true"> yyy
1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
6
by: Tjerk Wolterink | last post by:
Given an node with path a/b how do i get the next three following sibling nodes? example document <a> <b id="1"/> <b/> <b/>
3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
2
by: gimme_this_gimme_that | last post by:
What xpath expression would return the category-item having uid sps002 ? <category-list> <category> <uid>GRIDS_MAIN_CATEGORY_UID</uid> <uid-type>Categories</uid-type> <category-item-list>...
7
by: steve bull | last post by:
I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed below. string expr = "/swatches/colorRangeSwatch/colorRange";...
2
by: Steve Jorgensen | last post by:
Working with the DOM (specifically, the MSXML DOM), I'm wondering if there's an efficient way to check whether it would be matched by a given XPath expression. I've made it work to just run the...
1
by: Seong-Tae Jeong | last post by:
for example, xml document is below, It has a default namespace "xmlns='qwer://test'". string xmlText = "<test xmlns='http://test'><clear/><clear/></test>"; I would like to select node list...
1
by: Rob | last post by:
Hi, I am moving through an XML document using an XPath Navigator, and I'd like to be able to get the xpath expression for the location of the current node from the root node. Any ideas how to...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.