XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
seb lemmingSubject: choosing namespace....
Author: seb lemming
Date: 29 Mar 2007 01:53 AM
Dear all,

I try to transform two xml's that have the same structure, but with
a different namespace.
To do so I 'switch' on the namespace for a element that is always in the
xml and call the template that applies for this namespace.
I would like to call an other template that is the same for both the xml's. However since the xml namespace are diffirent I would like to set the namespace declaration in xsl dynamicly.
Example (which clears up my story big time):

[xml 1]
<LALA xmlns:ns2="http://test/v_0_2">
<ns2:ACTIONCODE>actie code 2</ns2:ACTIONCODE>
<ns2:test>test 2</ns2:test>
</LALA>

[xml 2]
<LALA xmlns:ns1="http://test/v_0_1">
<ns1:ACTIONCODE>actie code </ns1:ACTIONCODE>
<ns1:test>test 1</ns1:test>
</LALA>

[xsl]

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
>
<xsl:variable name="source_namespace" select="namespace-uri(//*[local-name()='ACTIONCODE'])"/>

<!-- test determ which template must be used for the message -->
<xsl:template match="/">
<wrapper>
<namespace-detected>
<xsl:value-of select="$source_namespace"/>
</namespace-detected>
<!-- switch here -->
<xsl:choose>
<xsl:when test="$source_namespace='http://test/v_0_1'">
<xsl:call-template name="test"/>
</xsl:when>
<xsl:when test="$source_namespace='http://test/v_0_2'">
<xsl:call-template name="test2"/>
</xsl:when>
</xsl:choose>
</wrapper>
</xsl:template>

<!-- Templates for all each known message type -->

<xsl:template name="test">
<test>
<xsl:call-template name="common"/>
</test>
</xsl:template>

<xsl:template name="test2">
<test2>
<xsl:call-template name="common"/>
</test2>
</xsl:template>

<!--
<xsl:template name="common" xmlns:source="http://test/v_0_1"> work
<xsl:template name="common" xmlns:source="xsl:value-of select="$source_namespace""> doesnt work
-->
<xsl:template name="common" xmlns:source="$source_namespace"><!-- does not work-->
<namespace-detected>
<xsl:value-of select="$source_namespace"/>
</namespace-detected>

<common>
<!--<xsl:value-of select="//*[local-name()='test']"/>--> works..
<xsl:value-of select="//source:test"/><!-- doesnt work-->
</common>
</xsl:template>

</xsl:stylesheet>

Posttop
(Deleted User) Subject: choosing namespace....
Author: (Deleted User)
Date: 30 Mar 2007 07:57 AM
Hi Seb,
you cannot define a namespace prefix using variables (xmlns:source is an XML definition, so it must be processed before the XSLT engine has even started looking at template, variables and so on). You can try using XSLT 2.0 and match expressions like *:common that will select a 'common' node from any namespace.

Hope this helps,
Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.