473,804 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(Noob) Working with namespaces in XSLT

Hi All

I am re-visiting XSLT after not touching it for about three years, so
to be honest I am starting myself from scratch.

If I have XML under the namespace "http://tempuri.com/abc/2002/09",
should I declare this at the top of my XSLT?

Additionally, if I have the following XML:

<myxmlroot xmlns="http://tempuri.com/abc/2002/09">
<header somevalue="" anotherval="" />
<mainbody>
<repeateditem id="0">Zero</repeateditem>
<repeateditem id="1">One</repeateditem>
<repeateditem id="2">Two</repeateditem>
</mainbody>
</myxmlroot>

Where am I going wrong in my XSLT?

<xsl:for-each select="/myxmlroot/mainbody">
Loop<br />
</xsl:for-each>

That doesn't seem to give me any output - hence my question about the
namespace.

Many thanks

Darren

May 23 '06 #1
2 1297
daz_oldham wrote:
If I have XML under the namespace "http://tempuri.com/abc/2002/09",
should I declare this at the top of my XSLT?


Yes. Bind it to a prefix. Then use that prefix in your XPaths, even if
you used the xmlns= shorthand in your documents; XSLT has no concept of
default namespace, so all references to namespaced elements and
attributes must use prefixed names.

<xsl:for-each select="/myns:myxmlroot/myns:mainbody"
xmlns:myns="htt p://tempuri.com/abc/2002/09">
Loop<br />
</xsl:for-each>

(In most cases you'd declare the prefix at the top of the stylesheet;
I'm doing it here just for illustrative purposes.)
May 23 '06 #2
Thanks Joe

I have that working now :)

Well, I do have futher problems, but I'll have a proper bash at them
before I post again!

Daz

May 23 '06 #3

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

Similar topics

6
4571
by: Joe Price | last post by:
Hi all I've formatted one of my xml files for viewing through a web browser using xsl. It works fine in Internet Explorer, however when I use Netscape6 or Opera to view the same page the disable-output-escaping function does not work and it is displaying html tags as text rather than code. Can anyone enlighten me as to why this is happening? Am i using the wrong namespace? i'm currently using:
5
4399
by: Steve Jorgensen | last post by:
I was having a bear of a time today trying to figure out some inconsistent behavior selecting nodes from and MSXML DOM document, so I distilled the issue down to a trivial test demonstrating the confusing behavior. The deal is that I want to create most of my XML nodes from code using createNode, but the code is much more clear if I can start by building the basic skeleton of the document using a simple XML string. The catch is, I'll...
2
2477
by: Jon Davis | last post by:
I would like to parse RSS 1.0 (not RSS 2.0) files. But I don't know how to work with these XML namespaces! And when namespaces are improperly used in RSS 2.0 files, I don't know how to deal with them and exceptions keep getting thrown! Does anyone have a tutorial or know of one that deals with XML namespaces with the .NET framework, preferably in C#, or maybe a good book to read? I just got my hands on Applied XML Programming for Microsoft...
19
16226
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org" xmlns:sns="http://www.test.org/sub" xmlns:mns="http://www.test.org/mini"> <data>
1
1235
by: dllhell | last post by:
Hi all, yeah... I know it's a noob question but... I have two projects: EXEproject and DLLproject. DLLproject is added to EXEproject but I can't reach DLLproject's namespace in EXEproject. It will be even better when I can put both namespaces under common namespace e.g. CommonNamespace.EXEproject.something and CommonNamespace.DLLproject.something
1
2769
by: GREGSMITH | last post by:
Hi all, I have an xml file that I am trying to run through XSLT, but the namespace on some of my source objects are causing the xslt to not find the node. Can't I tell xslt to ignore the namespace? xml file snippet: <Shipping xmlns="http://soa.channeladvisor.com/webservices/"> <NameTitle>Mr.</NameTitle> <FirstName>John</FirstName> <LastName>Doe</LastName> </Shipping> xslt snippet:
2
1621
by: lanegroups | last post by:
Dear experts, I'm trying to do the following using Xalan-C++ API 1. parse an XML document 2. evaluate an XML path 3. serialize the selected XML subtree 4. The new serialized XML fragment should have the correct namespace declared, based on their declaration from the original XML document. Task 1-3 are done and I'm using the traverseSubtree method from FormatterTreeWalker class to serialize the subtree. However, the
5
1517
by: printdude1968 | last post by:
Hi Everyone... I'm a newbie to this stuff so bear with me. I have a well formed xml document (I use jdom to verify) <?xml version="1.0" encoding="ISO-8859-1"?> <print-control> <destinations xmlns:destination0="http://mydomain.com/destinations/dest0"
3
2880
by: Lee | last post by:
Hello guys, I am new to XML and working on a XSLT to transforn yahoo shopping search result to html. my problem is the return XML contain xmlns in root element, here is the sample xml: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="aproductsearch.xslt"?> <ProductSearch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:aprods" xsi:schemaLocation="urn:yahoo:aprods...
0
10600
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
10350
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
10351
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
10096
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...
1
7638
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
5534
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...
1
4311
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
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
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.