xsl-list
[Top] [All Lists]

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

2006-02-06 06:19:52
On 2/6/06, Andrew Ballantine 
<andrew(_dot_)ballantine(_at_)assureweb(_dot_)co(_dot_)uk> 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="http://www.valid_url.com";>

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" 
xmlns:userDefined="http://mycompany.com/mynamespace"; 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
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="http://www.valid_url.com";  ...>

and

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

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

cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--