This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Generating namespace declarations given a result tree?


On Wed, 17 May 2000 09:39:04 +0100 (BST) David Carlisle 
<davidc@nag.co.uk> wrote:

> > 1. Are you supposed to output a namespace declaration for each 
> > namespace node
> 
> XSLT gives you no way of creating a namespace declaration.

I understand this but I am writing an xslt processor, not a stylesheet 
and so I am in fact creating namespace declarations when writing out 
the result tree.  

> When the result tree is linearised, the processor will add whatever
> namespace declarations are needed to ensure that the nodes end up in the
> right namespace if the linerised result is reparsed as an XMl document.

This information can come from namespaces on the 
elements and attributes.  It could also come from namespace nodes in 
the result tree.  

> > 2. Does it matter what prefixes are used (this includes using the
> > default namespace)? 
> 
> No

From reading the spec I would agree with this but see below.

> > 3. Is there a convention on removing unused namespaces?
> 
> decare namespaces you have used in the source or stylesheet but don't
> use in the output using exclude-result-prefixes, thenthe processor
> should not add any declarations for those.

Absolutely but there are namespace declarations in the source trees and
stylesheets that may not be  referenced in the result trees directly by 
element or attribute names.

Here is an example of what I mean.

Apply this stylesheet

<xsl:stylesheet 
   version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match = "/">
   <xsl:copy-of select = "/document/element[1]"/>
</xsl:template>
</xsl:stylesheet>

To this xml

<document>
<element pos = "1"
  xmlns:jpns1="http://www.messagingdirect.com/xml_namespaces/test1"
  xmlns:jpns2="http://www.messagingdirect.com/xml_namespaces/test2"
  xmlns:jpns3="http://www.messagingdirect.com/xml_namespaces/test3"
  an_attribute = "jpns3:some_function()"
/>
</document>

XT gives the following output (I have added whitespace)

<?xml version="1.0" encoding="utf-8"?>
<element
  pos="1"
  an_attribute="jpns3:some_function()"

  xmlns:jpns1="http://www.messagingdirect.com/xml_namespaces/test1"
  xmlns:jpns2="http://www.messagingdirect.com/xml_namespaces/test2"
  xmlns:jpns3="http://www.messagingdirect.com/xml_namespaces/test3"
/>

Here none of the namespaces declared in the source tree are actually 
used in the xml so the output has redundant namespace declarations.  
However in this case the namespaces could be used by a meta parser to 
correclty interpret the attribute value.  This is the way xslt works 
with qnames in xpath expressions. XT in this case has also preserved the
original namespace prefixes.

My question I guess boils down to this.  Is this just a feature that 
James Clark built into XT to get this extra functionality, or does the 
xslt spec gives some advice on this matter?

Any comments from XSLT implementors on this?

						Thanks
						   John-Paul
----------------------
John-Paul Sicotte
Software Composer
MessagingDirect
mailto:John-Paul@MessagingDirect.com



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]