Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts

    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.
    Last edited by mlse; 01-30-2009 at 02:22 PM. Reason: clarity
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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".

  • #3
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Ah! thanks for that ... so the two examples really are equivalent
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •