[xsl] XPath matching elements with or without prefix by inherited namespace

Subject: [xsl] XPath matching elements with or without prefix by inherited namespace
From: "Stephen Colin (UK)" <Colin.Stephen@xxxxxx>
Date: Fri, 11 Jan 2008 14:54:31 -0000
I'm sure this must be a common problem, but I've been unable to find any
reference to it.

How do I reliably match the "elem" element in both of the below

<?xml version="1.0" encoding="UTF-8?>
<p:example xmlns:p="something">

<?xml version="1.0" encoding="UTF-8?>
<p:example xmlns:p="something">

I believe that these are effectively identical as the prefix on elem in
the latter case is
redundant and same the namespace definition is inherited from p:example.

However the following will only match one and not the other (as though
the latter cases had no namespace associated with the <elem>).

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xsmlns:q="something">
  <xsl:value-of select="//elem"/>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xsmlns:q="something">
  <xsl:value-of select="//q:elem"/>

I'm confused, as if I use some xslt to show the namespaces on the node
in each case their identical:

 xml -> http://www.w3.org/XML/1998/namespace
 p   -> something

I get the same result with either Saxon 6.5.3 or xsltproc -
libxml(20628), libxslt(10120), libexslt(813)

I'm wanting to use XPath expressions to robustly handle SOAP requests in
either form.

Is it that only the definitions are inherited and the child elements
need to have the prefix to be explicitly put into that namespace ?

Many thanks,


Colin Stephen
ISD - Data Delivery Development Team (DDT)
Tel: +44 (0) 1753 564534
Mob: +44 (0) 7801 850728

This electronic message contains information from O2 which may be privileged
or confidential. The information is intended to be for the use of the
individual(s) or entity named above. If you are not the intended recipient be
aware that any disclosure, copying distribution or use of the contents of this
information is prohibited. If you have received this electronic message in
error, please notify us by telephone or email (to the numbers or address
below) immediately.

Switchboard: +44 (0)113 272 2000
O2 (UK) Limited 260 Bath Road, Slough, Berkshire SL1 4DX Registered in England
and Wales: 1743099. VAT number: GB 778 6037 85

Current Thread