Subject: Re: [xsl] namespaces problem - two transformations in one stylesheet possible?|
From: "Andrew Ballantine" <andrew.ballantine@xxxxxxxxxxxxxxx>
Date: Tue, 7 Feb 2006 14:34:00 -0000
Date: Mon, 6 Feb 2006 13:19:52 +0000 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx From: andrew welch <andrew.j.welch@xxxxxxxxx> Subject: Re: [xsl] namespaces problem - two transformations in one stylesheet possible? Message-ID: <74a894af0602060519h7f9058dfy64dea7658e792943@xxxxxxxxxxxxxx> On 2/6/06, Andrew Ballantine <andrew.ballantine@xxxxxxxxxxxxxxx> wrote: > Hi there, > > I have a problem with (unqualified) namespaces in the xml to be transform= ed that is preventing a transformation from working. I understand that is i= s possible to use a transformation to remove the namespaces, and then the r= esult 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 normall= y have been expected. > > Can I ask if it is therefore possible either to perform two transformatio= ns on the one stylesheet (i.e. to transform the incoming xml, and then tran= sform the result of this first transformation), or alternatively is it poss= ible 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=3D"1.0" encoding=3D"UTF-8"?> > <message xmlns=3D"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=3D"1.0" xmlns:userDefined=3D"http://mycompany.com= /mynamespace" xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt" xmlns:xsl=3D"h= ttp://www.w3.org/1999/XSL/Transform" exclude-result-prefixes=3D"msxsl" exte= nsion-element-prefixes=3D"userDefined"> > <xsl:output method=3D"xml" indent=3D"yes" omit-xml-declaration=3D= "no"/> > <xsl:template match=3D"/"> > <xsl:apply-templates select=3D"message"/> > </xsl:template> > <xsl:template match=3D"message"> > <xsl:apply-templates select=3D"m_content"/> > </xsl:template> > <xsl:template match=3D"m_content"> > <quotation dtd-version=3D"1.0"> > <versn>2.0</versn> > <xsl:call-template name=3D"control"/> > <!-- assorted other templates --> > </quotation> > </xsl:template> > <!-- Quotes/control --> > <xsl:template name=3D"control"> > <!-- etc lots more xsl here --> > </xsl:template> > </xsl:stylesheet> > > As stated the stylesheet does not like the namespace and fails to transfo= rm 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 appreciate= d. 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=3D"http://www.valid_url.com" ...> and <xsl:template match=3D"msg:message"> As far as I can see that's all your problem is... no need for two passes. cheers andrew Sorry andrew, but this has been tried and does not seem to work. Is there something I am missing here, or is my original question valid? This e-mail is private and confidential and is protected by copyright. It may also be privileged or otherwise protected by other legal rules. Access by or disclosure to anyone other than the intended recipient for any reason other than the business purpose for which the message is intended, is unauthorised. If you receive it in error, notify us, delete it and do not make use of or copy it. Internet communications are not secure and therefore Assureweb Limited do not accept legal responsibility for the contents of this message. Any views or opinions presented are solely those of the author and do not necessarily represent those of Assureweb Limited unless otherwise specifically stated.