XPath tool and namespace

Here should go questions about transforming XML with XSLT and FOP.
john99
Posts: 15
Joined: Fri Mar 09, 2012 2:42 pm

XPath tool and namespace

Post 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
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: XPath tool and namespace

Post by adrian »

Hello,

For all row elements from any namespace use:

Code: Select all

//*:row
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
john99
Posts: 15
Joined: Fri Mar 09, 2012 2:42 pm

Re: XPath tool and namespace

Post 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
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: XPath tool and namespace

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
john99
Posts: 15
Joined: Fri Mar 09, 2012 2:42 pm

Re: XPath tool and namespace

Post by john99 »

Thanks a bunch Adrian. I'm a noob in XSLT :). Been reading stuff.
Post Reply