Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Xpath: select namespace

Reply
Thread Tools

Xpath: select namespace

 
 
Tjerk Wolterink
Guest
Posts: n/a
 
      11-17-2004
IU have the following xsl root element:

<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlnsage="http://www.wolterinkwebdesign.com/xml/page"
xmlnsc="http://www.wolterinkwebdesign.com/xml/xcontent">


Well how do i select the xhtml namespace with xpath
I need it to use in a xpath expression like this:

*[namespace-uri(.) == namespace:c]

But namespace:c' should be the namespace of xhtml. Pleas help
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-17-2004


Tjerk Wolterink wrote:

> IU have the following xsl root element:
>
> <xsl:stylesheet version="1.0"
> xmlns="http://www.w3.org/1999/xhtml"
> xmlnssl="http://www.w3.org/1999/XSL/Transform"
> xmlnsage="http://www.wolterinkwebdesign.com/xml/page"
> xmlnsc="http://www.wolterinkwebdesign.com/xml/xcontent">
>
>
> Well how do i select the xhtml namespace with xpath
> I need it to use in a xpath expression like this:
>
> *[namespace-uri(.) == namespace:c]
>
> But namespace:c' should be the namespace of xhtml.


You need to declare a namespace prefix for XHTML e.g.

<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlnshtml="http://www.w3.org/1999/xhtml"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlnsage="http://www.wolterinkwebdesign.com/xml/page"
xmlnsc="http://www.wolterinkwebdesign.com/xml/xcontent">

then you can use that prefix e.g.
<xsl:template match="xhtml:*">
to match elements in that namespace.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      11-17-2004
Tjerk Wolterink <(E-Mail Removed)> writes:

> IU have the following xsl root element:
>
> <xsl:stylesheet version="1.0"
> xmlns="http://www.w3.org/1999/xhtml"
> xmlnssl="http://www.w3.org/1999/XSL/Transform"
> xmlnsage="http://www.wolterinkwebdesign.com/xml/page"
> xmlnsc="http://www.wolterinkwebdesign.com/xml/xcontent">
>
>
> Well how do i select the xhtml namespace with xpath
> I need it to use in a xpath expression like this:
>
> *[namespace-uri(.) == namespace:c]
>
> But namespace:c' should be the namespace of xhtml. Pleas help


since it's a constant you don't need to extract it from the source
you can just use
*[namespace-uri(.) = 'http://www.w3.org/1999/xhtml']


although as I said earlier it's simpler and more efficient (probably) to
write that as
h:*
and add
xmlns:h="http://www.w3.org/1999/xhtml"
to your xsl:stylesheet.


even in the xc case

*[namespace-uri(.) = namespace:c]

is rather dangerous as it forces a dependency on the prefixes used in
the source, whereas normally in XPath a source document can use any
prefix.

given your xsl:stylesheet above then the Xpath

xc:*

selects any element in the namespace
http://www.wolterinkwebdesign.com/xml/xcontent
which is what you want.

However

*[namespace-uri(.) = namespace:c]

selects any element whose namespace is bound to the prefix xc
in the source file. (So it might match MathML or XHTML or SVG or any
other namespace, if that namespace happens to be bound to the prefix xc
in the document)

David

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR CS0234: The type or namespace name 'DataAccessHelper' does not exist in the namespace 'BCC' (are you missing an assembly reference?) li.eddie@gmail.com ASP .Net 0 01-06-2006 11:31 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM
Namespace: Is it a scope or a namespace? Anonymous C++ 3 08-18-2003 01:31 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. ASP .Net 1 07-29-2003 04:31 PM



Advertisments