OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] namespaces & xslt newbie question

[ Lists Home | Date Index | Thread Index ]

XSLT specific questions have more chances to be answered in more 
appropriate lists. A couple of those are

www.mulberrytech.com/xsl/xsl-list/
http://www.topxml.com/xsltalk/default.asp

About your question now, your stylesheet must be aware of the namespace:

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


And then modify your XPath expressions to include the namespace, using 
the prefix you have assosiated it with:

<xsl:template match="/myPrefix:root">


hth,

Manos


[Gauthier@Wisard] wrote:
> Hello, I'm new to XSLT and I encounter problems with the use of namespaces
> I wish to transform my documents with msxsl (msxml wrapper), I use windows 2000 and msxml 4.0 SP1
> 
> My input file use a namespace for his root element (xmlns="documenttype1") and the transformation
> doesn't perform if I don't remove the namespace (else the <xsl:template> from the xsl doesn't apply)
> 
> If anyone could give a hand, I'm begining with namespace in xsl
> 
> Thanks alot
> 
> Gauthier
> 
> INPUT:
> =======================================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <root xmlns="documenttype1">
> <elm1>Value1</elm1>
> </root>
> =======================================
> 
> STYLESHEET:
> =======================================
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>  <xsl:output method="xml" encoding="ISO-8859-1" version="1.0" omit-xml-declaration="no"
> indent="yes"/>
> 
>  <!-- match la racine -->
>  <xsl:template match="/">
>   <xsl:element namespace="documenttype2" name="page">
>    <xsl:apply-templates select="/root/*"/>
>   </xsl:element>
>  </xsl:template>
>  <!-- match tout les fils de root -->
>  <xsl:template match="/root/*">
>   <xsl:copy-of select="."/>
>  </xsl:template>
> </xsl:stylesheet>
> =======================================
> 
> OUTPUT with namespace in the source xml root element
> =======================================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <page xmlns="documenttype2"></page>
> =======================================
> 
> OUTPUT without namespace in the source xml root element
> =======================================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <page xmlns="documenttype2">
> <elm1 xmlns="">Value1</elm1>
> </page>
> =======================================
> 
> Desired OUTPUT
> =======================================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <page xmlns="documenttype2">
> <elm1>Value1</elm1>
> </page>
> =======================================
> 
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
> 
> 





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS