View Full Version : XPath and namespaces

01-30-2009, 03:06 PM
Hi all,

This question is a follow-on from the one I posted here (http://www.codingforums.com/showthread.php?p=776079#post776079).

Consider the following equivalent XML fragments:

<aaa xmlns="http:www.whatever.com">
<bbb />

<root xmlns:x="http:www.whatever.com">
<x:bbb />

So, what would be the xpath for extracting "bbb" in each case? Would it be the same in each case? I hope it would be the same in each case because the two cases are equivalent.

EDIT: My instictive reaction in the second case is to write /root/x:aaa/x:bbb, but this would not work for the first case.

01-31-2009, 01:10 AM
If you redeclare the aaa prefix in your XSLT document on the root element, like:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.whatever.com">

Then, your XPath can look like "/root/x:aaa/x:bbb".

05-15-2009, 12:42 PM
Ah! thanks for that ... so the two examples really are equivalent :)