...

View Full Version : XPath and namespaces



mlse
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:


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


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

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.

jkd
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".

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum