473,320 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XSL namespace problem

Hi,
I have the follwing XML and XSL files, i want to do XSL transformation but
its not working because of the presence of xmlns="Science" in the Envelope
element, It works fine after removing it.

I want to know how do i specify this namespace in XSL.

file.xml
<?xmlversion ="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xml" href="file.xsl"?>
<Envelope
xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
Name></Header></Envelope>
file.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">
<xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>
<xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>
</xsl:stylesheet>

Thanks
Dec 15 '05 #1
3 1368


Sandy wrote:

<?xml-stylesheet type="text/xml" href="file.xsl"?>
<Envelope
xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
Name></Header></Envelope> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">
Use
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sc="Science"
and then
<xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>
<xsl:template match="sc:Envelope">
<xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>


<xsl:template match="sc:Header"><xsl:value-of select="sc:class" />

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 15 '05 #2
Try something like that :

<xsl:stylesheet version="1.0"
xmlns:xsl="..." xmlns:env="Science">
<xsl:template match="env:Envelope"><xsl:apply-templates/></xsl:template>
<xsl:template match="env:Header"><xsl:value-of
select="class"/></xsl:template>
</xsl:stylesheet>

Best regards,

A.Brillant
EditiX - XML Editor and XSLT Debugger
http://www.editix.com
Sandy wrote:
Hi,
I have the follwing XML and XSL files, i want to do XSL transformation but
its not working because of the presence of xmlns="Science" in the Envelope
element, It works fine after removing it.

I want to know how do i specify this namespace in XSL.

file.xml
<?xmlversion ="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xml" href="file.xsl"?>
<Envelope
xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
Name></Header></Envelope>
file.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">
<xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>
<xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>
</xsl:stylesheet>

Thanks

Dec 16 '05 #3
Sandy wrote:
Hi,
I have the follwing XML and XSL files, i want to do XSL transformation but
its not working because of the presence of xmlns="Science" in the Envelope
element, It works fine after removing it.
in XML, non-prefixed names are endorsing the default namespace, which is
"Science" in your case
namespaces are working like families :
-<Envelope> is the firstname
-"Science" is the familyname

in XPath, non-prefixed names have no namespace
thus, in XSLT, as match="Envelope" is used without namespaces, it means
that you refer to :
-<Envelope> as the firstname
-no familyname

which is not the element that you have in your source document

in your XSLT document, you must deal with the XPath requirements :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="Science">
^^^^^^^^^

<xsl:template match="foo:Envelope"><xsl:apply-templates/></xsl:template>
<xsl:template match="foo:Header"><xsl:value-of
select="foo:class"/></xsl:template>
</xsl:stylesheet>

-----------------------

notice that xmlns declarations should be non-relative URIs
URIs are just universal identifiers, that enforce familynames to be unique

xmlns="Science" is totally useless, because it might be not unique
xmlns="http://yourcompany.com/Science" is universally unique and ensures
that a name defined with :
-<Envelope>
-"http://yourcompany.com/Science"
can't be ambiguous

I want to know how do i specify this namespace in XSL.

file.xml
<?xmlversion ="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xml" href="file.xsl"?>
<Envelope
xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
Name></Header></Envelope>
file.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">
<xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>
<xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>
</xsl:stylesheet>

Thanks

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Dec 21 '05 #4

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

Similar topics

8
by: Marcin Kalicinski | last post by:
Is the code below ill formed (because operator >> is defined in different namespace than class B)? It fails with VS 2005 Beta. I don't know if I should redesign my code or if I should find a...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
5
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
0
by: richwangler | last post by:
This problem should be easily reproducable if anybody has the time. I need to build the following XML programatically and decided to use the XMLSerializer. I simplified the XML (myExample.xml)...
5
by: Mike Oliszewski | last post by:
Given the following c# code: namespace Company2 { public class SomeFunctions { public void FunctionA() { // Do Something. }
10
by: anders | last post by:
I have 2 external assemblies A1 and A2 that both define class X in the global namespace. I need to use both assemblies in my VB project but the names X are ambiguous. How can I get around this...
4
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
by: George | last post by:
I am currently developing an xbrl validation software that takes an xml instance file and a lot of schemas(xsd files) and validates it against the xsd files. I am using Visual basic in visual...
7
by: Armin Zingler | last post by:
Hi all, I have a Form called "Main": Public Class Main Private Sub Button1_Click( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.