473,800 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Xpath: select namespace

IU have the following xsl root element:

<xsl:styleshe et version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:xc="http://www.wolterinkwe bdesign.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::xc]

But namespace::xc' should be the namespace of xhtml. Pleas help
Jul 20 '05 #1
2 4932


Tjerk Wolterink wrote:
IU have the following xsl root element:

<xsl:styleshe et version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:xc="http://www.wolterinkwe bdesign.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::xc]

But namespace::xc' should be the namespace of xhtml.


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

<xsl:styleshe et version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:xc="http://www.wolterinkwe bdesign.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/
Jul 20 '05 #2
Tjerk Wolterink <tj***@wolterin kwebdesign.com> writes:
IU have the following xsl root element:

<xsl:styleshe et version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:page="htt p://www.wolterinkwe bdesign.com/xml/page"
xmlns:xc="http://www.wolterinkwe bdesign.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::xc]

But namespace::xc' 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::xc]

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::xc]

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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2973
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the XPath expression to select the namespace nodes with prefix "foo"? And what's the XPath expression to select the
1
6854
by: Seong-Tae Jeong | last post by:
for example, xml document is below, It has a default namespace "xmlns='qwer://test'". string xmlText = "<test xmlns='http://test'><clear/><clear/></test>"; I would like to select node list "clear" with XPath Expression. XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml( xmlText );
1
1483
by: Sonu Kapoor | last post by:
Hi, I would like to use xpath with xslt. I know that this should be possible, but I dont get it ! Here is what I have tried so far: ==================================== my xml file: ====================================
5
2409
by: David Thielen | last post by:
Hi; I set up my xml as follows: XmlDocument xml = new XmlDocument(); xml.Load(File.Open("data.xml", FileMode.Open, FileAccess.Read)); XmlNamespaceManager context = new XmlNamespaceManager(xml.NameTable); context.AddNamespace("", "http://www.test.org"); context.AddNamespace("sns", "http://www.test.org/sub"); XmlNode node = xml.SelectSingleNode("/root", context);
3
4980
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
2
1793
by: Monty | last post by:
Despite reading posts in Google, I don't understand XPATH. Can someone help me write an XPATH. From Google I think my problem is that the default namespace does not have a prefix. I can't change this as I have received this XML and I didn't create it. All I want to is retrieve the PROJECTNAME from the following XML. I am typing this XML and XPATH into this site http://www.activsoftware.com/xml/xpath/ The XPATH that does not work is...
14
17209
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.