Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL namespace problem

Reply
Thread Tools

XSL namespace problem

 
 
Sandy
Guest
Posts: n/a
 
      12-15-2005
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"
xmlnssl="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


 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      12-15-2005
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"
xmlnssl="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"
> xmlnssl="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 |
-----------------------
 
Reply With Quote
 
 
 
 
JAPISoft
Guest
Posts: n/a
 
      12-15-2005
Try something like that :

<xsl:stylesheet version="1.0"
xmlnssl="..." 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"
> xmlnssl="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
>
>

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-15-2005


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"
> xmlnssl="http://www.w3.org/1999/XSL/Transform" xmlns="Science">


Use
<xsl:stylesheet
xmlnssl="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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR CS0234: The type or namespace name 'DataAccessHelper' does not exist in the namespace 'BCC' (are you missing an assembly reference?) li.eddie@gmail.com ASP .Net 0 01-06-2006 11:31 AM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Need help: Problem with XML/XSL namespace matching Lothar Lemnitzer XML 1 09-21-2004 02:47 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. ASP .Net 1 07-29-2003 04:31 PM



Advertisments