XSL namespace problem

S

Sandy

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
 
P

Philippe Poulard

Sandy said:
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 |
-----------------------
 
J

JAPISoft

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
 
M

Martin Honnen

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="Header"><xsl:value-of select="class"/></xsl:template>

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top