Re: [xsl] namespaces problem - two transformations in one stylesheet possible?

Subject: Re: [xsl] namespaces problem - two transformations in one stylesheet possible?
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Mon, 6 Feb 2006 13:19:52 +0000
On 2/6/06, Andrew Ballantine <andrew.ballantine@xxxxxxxxxxxxxxx> wrote:
> Hi there,
> I have a problem with (unqualified) namespaces in the xml to be transformed
that is preventing a transformation from working. I understand that is is
possible to use a transformation to remove the namespaces, and then the result
of this can then be transformed. However the architecture that we are using
does not make it easy to use two stylesheets where one would normally have
been expected.
> Can I ask if it is therefore possible either to perform two transformations
on the one stylesheet (i.e. to transform the incoming xml, and then transform
the result of this first transformation), or alternatively is it possible to
reference a second stylesheet in the first and then pass the result of the
first stylesheet to a second one?
> A code example:
> Incoming message (I have no control over this):
> <?xml version="1.0" encoding="UTF-8"?>
> <message xmlns="";>

elements are in this namespace ^^^^^^^^^^^^^^^^^^^^^^^

>         <m_control>
>                 <various_control_tags />
>         </m_control>
>         <m_content>
>                 <b_control>
>                         <various_other_control_tags />
>                 </b_control>
>                 <message_contents />
>         </m_content>
> </message>
> The existing stylesheet is something like the following:
> <xsl:stylesheet version="1.0"
exclude-result-prefixes="msxsl" extension-element-prefixes="userDefined">
>         <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
>         <xsl:template match="/">
>                 <xsl:apply-templates select="message"/>
>         </xsl:template>
>         <xsl:template match="message">
>                 <xsl:apply-templates select="m_content"/>
>         </xsl:template>
>         <xsl:template match="m_content">
>                 <quotation dtd-version="1.0">
>                         <versn>2.0</versn>
>                         <xsl:call-template name="control"/>
>                         <!-- assorted other templates -->
>                 </quotation>
>         </xsl:template>
>         <!--  Quotes/control -->
>         <xsl:template name="control">
>                 <!-- etc lots more xsl here -->
>         </xsl:template>
> </xsl:stylesheet>
> As stated the stylesheet does not like the namespace and fails to transform
as expected, and we are currently very limited by our architecture as to what
we can do about this. Any help or advice with this is much appreciated.

You haven't defined the namespace in your stylesheet - you won't be
able to match any elements in that namespace until you define it and
give it a prefix, and then adjust your match patterns:

<xsl:stylesheet xmlns:msg="";  ...>


<xsl:template match="msg:message">

As far as I can see that's all your problem is... no need for two passes.


Current Thread