RE: [xsl] [XSL] copying namesapces with prefix "xmlns:".

Subject: RE: [xsl] [XSL] copying namesapces with prefix "xmlns:".
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 26 Aug 2005 13:31:16 +0100
<xsl:element name="definitions">
         <xsl:copy-of select="namespace::*"/>

What namespace do you want the <definitions> element to be in? Specify the
namespace like this:

<xsl:element name="definitions" namespace="http://whatever";>

The element name has two parts, a local name and a namespace URI, and these
are determined by the name and namespace attributes of xsl:element. You
can't change the name of the element subsequently by adding namespace nodes
to it.

It's very rarely necessary to add namespace nodes to the result tree
explicitly. It's usually needed only when you result document contains
"QNames in content" - references to namespace prefixes in the content of
text and attribute nodes. Most documents use namespace prefixes only in
element and attribute names, and those namespaces will be declared
automatically if you give your elements and attributes the right
(namespace-qualified) names. Your result document doesn't have any
QNames-in-content, so I don't know why you need all these namespaces to be
declared.

Having said that, I don't think your XSLT processor is handling the copy-of
correctly - which processor is it?

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: siva [mailto:siva@xxxxxxx] 
> Sent: 26 August 2005 12:18
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] [XSL] copying namesapces with prefix "xmlns:".
> 
> here they are ...
> 
> My xsl file:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
>  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
> version="1.0"  xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0";  
> xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; 
> xmlns:xs="http://www.w3.org/2001/XMLSchema";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xmlns="http://test.de/schemas/wfdl/";>
>  <xsl:output method="xml"/>    
> <xsl:template match="*">
>     <xsl:element name="definitions">
>         <xsl:copy-of select="namespace::*"/>
>         <xsl:element name="FlowModel"/>
>     </xsl:element>   
> </xsl:template>       
> </xsl:stylesheet>
> 
> Input.xml :
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Package Id="typeoperation" Name="typeoperation" 
> xmlns="http://www.wfmc.org/2002/XPDL1.0"; 
> xmlns:bo="http://test.de/bo/"; 
> xmlns:h2w="http://test.de/h2w/bo/"; 
> xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xsi:schemaLocation="http://www.wfmc.org/2002/XPDL1.0 
> http://wfmc.org/standards/docs/TC-1025_schema_10_xpdl.xsd";>
>     <PackageHeader>
>         <XPDLVersion>1.0</XPDLVersion>
>         <Vendor>Together</Vendor>
>         <Created>2005-08-23 17:23:04</Created>
>     </PackageHeader>
> </Package>
> 
> And Output.xml without xmlns:bo="http://test.de/bo/"; 
> xmlns:h2w="http://test.de/h2w/bo/":
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <definitions xmlns="http://test.de/schemas/wfdl/"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
> xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; 
> xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0";>
>     <FlowModel/>
> </definitions>
> 
> 
> Regards, Siva
> 
> David Carlisle wrote:
> 
> >>and this command copied all the attributes except the 
> attributes starts 
> >>with "xmlns:".  This is okay.
> >>    
> >>
> >
> >yes, namespace declarations are not attributes to XSLT.
> >
> >  
> >
> >>But nothing is copied if i use this.
> >>
> >><xsl:copy-of select="namespace::*"/>
> >>    
> >>
> >
> >
> >Then either there is a bug in your system (which are you 
> using) or there
> >is a bug in your stylesheet (post a 3 line input file and 
> complete, small,
> >stylesheet that shows the problem. Without seeing more, we can't say.
> >
> >David
> >
> >
> >_____________________________________________________________
> ___________
> >This e-mail has been scanned for all viruses by Star. The
> >service is powered by MessageLabs. For more information on a 
> proactive
> >anti-virus service working around the clock, around the globe, visit:
> >http://www.star.net.uk
> >_____________________________________________________________
> ___________

Current Thread