Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2009, 02:06 PM   PM User | #1
mlse
Regular Coder

 
mlse's Avatar
 
Join Date: Mar 2005
Posts: 624
Thanks: 20
Thanked 19 Times in 18 Posts
mlse is on a distinguished road
XPath and namespaces

Hi all,

This question is a follow-on from the one I posted here.

Consider the following equivalent XML fragments:

Code:
<root>
  <aaa xmlns="http:www.whatever.com">
    <bbb />
  </aaa>
</root>
Code:
<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.
__________________
Die Welt ist ein Irrenhaus und hier ist die Zentrale!

Last edited by mlse; 01-30-2009 at 02:22 PM.. Reason: clarity
mlse is offline   Reply With Quote
Old 01-31-2009, 12:10 AM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
If you redeclare the aaa prefix in your XSLT document on the root element, like:
Code:
<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".
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 05-15-2009, 11:42 AM   PM User | #3
mlse
Regular Coder

 
mlse's Avatar
 
Join Date: Mar 2005
Posts: 624
Thanks: 20
Thanked 19 Times in 18 Posts
mlse is on a distinguished road
Ah! thanks for that ... so the two examples really are equivalent
__________________
Die Welt ist ein Irrenhaus und hier ist die Zentrale!
mlse is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:05 AM.


Advertisement
Log in to turn off these ads.