Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Adding unused namespace in output using xslt.

From: Jan Obrestad <obrestad@----------.--->
To: NULL
Date: 10/7/2008 2:02:00 PM

Martin Honnen wrote:
> Jan Obrestad wrote:
> 
>> Is it possible using xslt to add a namespace declaration in the output 
>> document? The declaration should be with prefix, like this: 
>> xmlns:ge="http://earth.google.com/kml/2.0"
> 
> 
> Sure, put it where you need it e.g.:
>   <xsl:template match="/">
>     <foo xmlns:ge="http://earth.google.com/kml/2.0">
>       <xsl:apply-templates/>
>     </foo>
>   </xsl:template>
> 
> Or simply doing
>   <xsl:stylesheet
>     xmlns:ge="http://earth.google.com/kml/2.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     version="1.0">
> 
>     <xsl:template match="/">
>       <foo>
>         <xsl:apply-templates/>
>       </foo>
>     </xsl:template>
> 
>   </xsl:stylesheet>
> 
> should suffice.
> 
> 
Thank you for a swift reply.

I tried your suggestion, but couldn't get it to work on my concrete 
problem.

My problem is this. I have this xslt:

<?xml version="1.0" encoding="UTF-8" ?>
<!--Stylesheet to strip element prefixes and declare e2b namespace as 
default-->
<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns="http://www.e2b.no/XMLSchema"
        xmlns:e2b="http://www.e2b.no/XMLSchema"
        >
   <xsl:output method="xml" indent="yes" encoding="iso-8859-1"/>
   <xsl:param name="params"/>
   <xsl:template match="node()">
     <xsl:element name="{local-name()}">
       <xsl:apply-templates select="./@*"/>
       <xsl:value-of select="text()"/>
       <xsl:apply-templates select="./*"/>
     </xsl:element>
   </xsl:template>
   <xsl:template match="@*">
     <xsl:attribute name="{local-name()}">
       <xsl:value-of select="."/>
     </xsl:attribute>
   </xsl:template>
</xsl:stylesheet>

This script removes the e2b prefix and make that namespace the default 
The root element then becomes:
<Interchange xmlns="http://www.e2b.no/XMLSchema">

But our client wants the root element to look like this:
<Interchange xmlns="http://www.e2b.no/XMLSchema" 
xmlns:e2bCard="http://www.e2b.no/XMLSchema/Card" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="e2b_Invoice_Interchange_v3p0.xsd">

I tried adding these namespaces to the xsl:styleshhet element, but they 
did not appear in the output xml.
Do you have any idea how to achieve this?








transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent