Re: [xsl] questions regd namespaces

Subject: Re: [xsl] questions regd namespaces
From: subbu@xxxxxxxxxxxx
Date: Tue, 09 Jul 2002 13:41:39 +0100
Hi Jeni,
I think i missed some point.
i have an xml 
<?xml version="1.0"?>
<center>
<all-centers xmlns = "http://www.nda-centres.com/namespaces";>
all centers of nda
</all-centers>
</center>
now if i want to print the all-centers text ie.. "all centers of nda"
should i declare the namespace in the xsl and then try to xsl:value-of the all-
centers element ??
i did something like
*******************************
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
xmlns="http://www.nda-centres.com/namespaces";>
<xsl:template match="/">
<xsl:value-of select="/center/all-centers"/>
<!-- HOW DO I PRINT THE XMLNS VALUE HERE ?? -->
</xsl:template>
</xsl:stylesheet>
*********************************
i am not getting the text of all-centers.. what is  missing??
The simplest way of doing
> that is to include a namespace declaration on the literal result
> element. For example:
> 
> <xsl:template match="/">
>   <all-centres xmlns="http://www.nda-centres.com/namespaces"; />
> </xsl:template>
I cant include the namespace here as u suggested because i am not sure of the 
namespace that the perticular xml element has.

Subbu

Quoting Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>:

> Hi Subbu,
> 
> > 1. Is xmlns treated different from a normal attribute??
> 
> Yes. 'xmlns' attributes don't count as attributes as far as the XSLT
> processor is concerned (either on input or output). The XSLT processor
> automatically adds namespace declarations to the output that you
> create based on the namespaces of and the namespace nodes on the
> elements in the result tree.
> 
> > 2. In my case how do i output the value of xmlns??
> 
> Well, the simplest way is to make sure that your all-centres element
> in the result is in the namespace
> 'http://www.nda-centres.com/namespaces'. The simplest way of doing
> that is to include a namespace declaration on the literal result
> element. For example:
> 
> <xsl:template match="/">
>   <all-centres xmlns="http://www.nda-centres.com/namespaces"; />
> </xsl:template>
> 
> But more usually you should declare the namespace on the
> xsl:stylesheet element as the default namespace for the stylesheet:
> 
> <xsl:stylesheet version="1.0"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                 xmlns="http://www.nda-centres.com/namespaces";>
> 
> <xsl:template match="/">
>   <all-centres />
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> > 3. How will someone benifit from using a namespace declaration??
> 
> That's a hard question to answer. The namespace of an element is an
> essential part of an element, so it's like asking "How will someone
> benefit from naming an element?" They'll benefit because the element
> will be recognised properly by applications that are built to process
> elements in that namespace. The point of namespaces in general is to
> enable you to have documents that mix elements from lots of different
> markup languages without getting confused about what a particular
> element means.
> 
> > 4. In the xsl:stylesheet instruction,
> > <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> > the above namespace allows some XSL functions where as the older
> version 
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";> does not
> allow some 
> > methods..
> > so where are these methods?? how does the processor know that the
> perticular 
> > namespace doesnt contain the method or does contain the method??where
> does it 
> > look for this information?
> 
> The XSLT processor has the methods (I assume you mean functions and
> elements) built into it. The XSLT processor knows which elements and
> functions it needs to use based on the namespace URI, which is
> hard-coded into the processor. The XSLT processor doesn't need to look
> anywhere to find this information -- it is programmed in by the
> implementer; the implementer found out what functions and elements
> need to be supported by reading the spec.
> 
> Cheers,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 


--------------------------------------------------------------
Sent with "Me-Mail", Boltblue's FREE mobile messaging service.
http://www.boltblue.com


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread