XPath tool and namespace

Here should go questions about transforming XML with XSLT and FOP.

XPath tool and namespace

Postby john99 » Fri Mar 09, 2012 2:46 pm

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
john99
 
Posts: 15
Joined: Fri Mar 09, 2012 2:42 pm

Re: XPath tool and namespace

Postby adrian » Fri Mar 09, 2012 4:00 pm

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

Re: XPath tool and namespace

Postby john99 » Fri Mar 09, 2012 4:07 pm

Thanks Adrian. How do I select table only without using * ?

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

TIA,

John
john99
 
Posts: 15
Joined: Fri Mar 09, 2012 2:42 pm

Re: XPath tool and namespace

Postby adrian » Fri Mar 09, 2012 4:22 pm

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

Re: XPath tool and namespace

Postby john99 » Fri Mar 09, 2012 4:28 pm

Thanks a bunch Adrian. I'm a noob in XSLT :). Been reading stuff.
john99
 
Posts: 15
Joined: Fri Mar 09, 2012 2:42 pm


Return to XSLT and FOP

Who is online

Users browsing this forum: No registered users and 0 guests