473,508 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT doesn't like xmlns?

I'm making my first steps with XSLT and run into a problem where I didn't
find an explanation yet for. Have a look at this very simple XML document
(DocBook) ...

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<book version="5.0">
<title>Title</title>
</book>

.... and another simple XSLT document (test.xslt):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><body>
<h1><xsl:value-of select="book/title" /></h1>
</body></html>
</xsl:template>
</xsl:stylesheet>

The problem is that if I add xmlns="http://docbook.org/ns/docbook" to the
book-element neither my XML editor (XML Notepad 2007) nor my browser
(Opera 9.26) show the book title anymore. However without xmlns my XML
editor doesn't know of course where the DocBook tags come from.

Is this a problem of my tools or XSLT simply doesn't like xmlns? In the
latter case is there any workaround?

Boris
Jun 27 '08 #1
2 2363
* Boris wrote in comp.text.xml:
>I'm making my first steps with XSLT and run into a problem where I didn't
find an explanation yet for. Have a look at this very simple XML document
(DocBook) ...

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<book version="5.0">
<title>Title</title>
</book>

... and another simple XSLT document (test.xslt):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><body>
<h1><xsl:value-of select="book/title" /></h1>
</body></html>
</xsl:template>
</xsl:stylesheet>

The problem is that if I add xmlns="http://docbook.org/ns/docbook" to the
book-element neither my XML editor (XML Notepad 2007) nor my browser
(Opera 9.26) show the book title anymore. However without xmlns my XML
editor doesn't know of course where the DocBook tags come from.
You have to declare that namespace and use the prefix to refer to the
elements, for example,

<xsl:stylesheet xmlns:d='http://docbook.org/ns/docbook' ...>
...
<xsl:value-of select="d:book/d:title" />
...

Bare names in XPath 1.0 always refer to an element in no namespace,
if you put them into one using the default namespace declaration, the
names change, but your paths still refer to the old names.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #2
XSLT is fully namespace-aware.
The problem is that if I add xmlns="http://docbook.org/ns/docbook" to
the book-element
By doing so, you have moved that element and all its children which
don't have prefixes into the docbook namespace. (See the XML Namespaces
specification for details, or a good modern XML tutorial.) To select a
namespaced node, XPath and XSLT must explicitly say that this is what
they're doing. Since XSLT 1.0 doesn't support the concept of a default
namespace, you must use prefixes to do this. For example, you could change
<xsl:value-of select="book/title" />
to
<xsl:value-of select="docbook:book/docbook:title"
xmlns:docbook="http://docbook.org/ns/docbook" />


neither my XML editor (XML Notepad 2007) nor my browser
(Opera 9.26) show the book title anymore. However without xmlns my XML
editor doesn't know of course where the DocBook tags come from.

Is this a problem of my tools or XSLT simply doesn't like xmlns? In the
latter case is there any workaround?

Boris
Jun 27 '08 #3

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

Similar topics

20
6732
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
13
6627
by: Mark Constant | last post by:
I posted this on topxml.com and nobody has responded so I was hoping somebody could help me here. I am following some tutorials in VS.NET. I created a XSD schema file and then from there created an...
12
3195
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
5
2861
by: Douglas Steen | last post by:
Here's what I have (in snippets) ** XML ** <parent> <child> <grandchild/> </child> </parent> ** XSLT ** <xsl:template match="/parent">
7
1270
by: One Handed Man \( OHM - Terry Burns \) | last post by:
I've been battling with this stupid problem for hours now. WebApp: Trying to do a simple transformation using XSLT to a Web Page, but it just failes without an error message ( In other words,...
18
2046
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
3
2309
by: Chrism2671 | last post by:
I'm new to XSLT/XML and I have a very simple, quick question. i've been trying to convert simple xml files into CSV files and have made a simple XSLT template using the w3 tutorials, but it doesn't...
1
3438
by: CAM123 | last post by:
I have added: <br><xsl:value-of select="Line" /></br> to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However...
0
7223
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,...
0
7377
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...
1
7036
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...
0
5624
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,...
1
5047
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...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
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...
0
1547
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 ...
0
414
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...

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.