RE: [xsl] Removing empty namespace definition from an element

Subject: RE: [xsl] Removing empty namespace definition from an element
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 5 Aug 2004 08:50:45 +0100
The basic message with problems like this is to make sure that your elements
are in the right namespace; if they are, the namespace declarations will
look after themselves. You have the unwanted namespace declaration because
you created the element in the wrong namespace.

If you use xsl:element to create an element, use the namespace attribute to
define what namespace you want it to be in. But in this case, you could
equally well use a literal result element.

Michael Kay  

> -----Original Message-----
> From: Joel Friedman [mailto:jfriedman@xxxxxxxxxxxx] 
> Sent: 04 August 2004 16:34
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Removing empty namespace definition from an element
> 
> I've learned quite a lot since my last post.  I've managed to 
> rework my
> XSL file in accordance with Mike Kay's suggestions.  I only have one
> obstacle left in my transformation.
> 
> Here is the beginning of my input XML:
> 
> <?xml version="1.0" encoding="utf-16"?>
> <sequence version="1" description="Deploy Server"
> command="DeployServer.xml"
> xmlns="http://schemas.microsoft.com/ads/2003/sequence";>
>   <task description="Launch Image Deployment Tool" doesReboot="false">
>     <command target="controller">C:\Patches\Tools\dpIDT.vbs</command>
>     <parameters>
>       <parameter>$device.system.name$</parameter>
>       <parameter>_osName_</parameter>
>     </parameters>
>   </task>
> 
> 
> And here is part of the relevant XSL:
> 
> xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>  
> xmlns:ads="http://schemas.microsoft.com/ads/2003/sequence";
>                 version="1.0">
> 
>   <xsl:output method="xml" indent="yes"/>
>   <xsl:variable name="osName" select="'WIN2K3'"/>
> 
>   <xsl:template match="/">
>     <xsl:apply-templates/>
>   </xsl:template>
> 
>   <xsl:template match="ads:parameter[.='_osName_']">
>     <xsl:element name="parameter"><xsl:value-of
> select="$osName"/></xsl:element>
>   </xsl:template>
> 
> 
> Now the match works just fine, the issue is the element 
> parameter looks
> like this in the output:
> 
> <task description="Launch Image Deployment Tool" doesReboot="false">
> <command target="controller">C:\Patches\Tools\dpIDT.vbs</command>
> <parameters>
> <parameter>$device.system.name$</parameter>
> <parameter xmlns="">WIN2K3</parameter>
> </parameters>
> </task>
> 
> My interpreter does not like the empty namespace declaration. 
>  The only
> way I have figured out how to get it to not show is by using this as a
> template instead:
> 
>   <xsl:template match="ads:parameter[.='_osName_']">
>     <xsl:text 
> disable-output-escaping="yes">&lt;parameter&gt;</xsl:text>
>         <xsl:value-of select="$osName"/>
>     <xsl:text
> disable-output-escaping="yes">&lt;/parameter&gt;</xsl:text>
>   </xsl:template>
> 
> 
> And that's REAL UGLY!
> 
> 
> Is there a better?  A real way, using XSLT logic?

Current Thread