Page 1 of 1

XPath tool and namespace

Posted: Fri Mar 09, 2012 2:46 pm
by john99
Hello,

I'm trying to use the XPath tool on the IDE. I have a simple XML with namespace like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<tables xmlns="aaaaa">
<table xmlns="bbbbb">
<row>A</row>
<row>B</row>
</table>
</tables>
How do I get all row using XPath on the IDE ?.

TIA,

John

Re: XPath tool and namespace

Posted: Fri Mar 09, 2012 4:00 pm
by adrian
Hello,

For all row elements from any namespace use:

Code: Select all

//*:row
Regards,
Adrian

Re: XPath tool and namespace

Posted: Fri Mar 09, 2012 4:07 pm
by john99
Thanks Adrian. How do I select table only without using * ?

/*:tables/bbbbb:table or /*:tables/.:table don't seem to work.

TIA,

John

Re: XPath tool and namespace

Posted: Fri Mar 09, 2012 4:22 pm
by adrian
How about:

Code: Select all

/tables/*:table
'*:' means from any namespace
If you want to use a specific namespace, declare a prefix mapping for it in: Options > Preferences, XML > XSLT-FO-XQuery > XPath, Default prefix-namespace mappings
myns "bbbbb"
Then use in the XPath toolbar:

Code: Select all

/tables/myns:table
Or if you don't want any namespace mappings, there's always the possibility of specifying both the namespace and the local name, but it's messy:

Code: Select all

/tables/*[namespace-uri()='bbbbb' and local-name()='table']
If you have just started using XPath, there are some tutorials here:
http://www.w3schools.com/xpath/

Regards,
Adrian

Re: XPath tool and namespace

Posted: Fri Mar 09, 2012 4:28 pm
by john99
Thanks a bunch Adrian. I'm a noob in XSLT :). Been reading stuff.