473,732 Members | 2,052 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 4928


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
2971
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
6851
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
2405
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
4979
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
1792
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
17139
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
8944
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
9443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9177
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8184
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...
1
6732
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4546
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
4803
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3258
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
3
2176
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.