Connecting Tech Pros Worldwide Help | Site Map

XSL namespace problem

Sandy
Guest
 
Posts: n/a
#1: Dec 15 '05
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


Martin Honnen
Guest
 
Posts: n/a
#2: Dec 15 '05

re: XSL namespace problem




Sandy wrote:

[color=blue]
> <?xml-stylesheet type="text/xml" href="file.xsl"?>
> <Envelope
> xmlns="Science"><Header><class>A</class><activityName>Run</activityName><msg
> Name></Header></Envelope>[/color]
[color=blue]
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">[/color]

Use
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sc="Science"
and then
[color=blue]
> <xsl:template match="Envelope"><xsl:apply-templates/></xsl:template>[/color]

<xsl:template match="sc:Envelope">
[color=blue]
> <xsl:template match="Header"><xsl:value-of select="class"/></xsl:template>[/color]

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

--

Martin Honnen
http://JavaScript.FAQTs.com/
JAPISoft
Guest
 
Posts: n/a
#3: Dec 16 '05

re: XSL namespace problem


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:[color=blue]
> 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
>
>[/color]
Philippe Poulard
Guest
 
Posts: n/a
#4: Dec 21 '05

re: XSL namespace problem


Sandy wrote:[color=blue]
> 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.[/color]

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
[color=blue]
>
> 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
>
>[/color]


--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Closed Thread