Hello :)
I am writing a small XSLT script to translate an incoming soap message to a simple xml data file. I am using Saxon9.
The input looks like this:
PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns:ContactWS_ContactQueryPage_Output
xmlns:ns="urn:crmondemand/ws/contact/">
<ns:LastPage>true</ns:LastPage>
<ListOfContact xmlns="urn:/crmondemand/xml/contact">
<Contact>
<ContactFirstName>Fred</ContactFirstName>
<IntegrationId>AAPA-1VPNO9</IntegrationId>
<ContactLastName>Johnson</ContactLastName>
</Contact>
</ListOfContact>
</ns:ContactWS_ContactQueryPage_Output>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The prefered output looks like this:
PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<data xmlns:saxon2="http://saxon.sf.net/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:n="urn:/crmondemand/xml/contact">
<object>
<property name="ContactFirstName">Fred</property>
<property name="replacewithidentifier">AAPA-1VPNO9</property>
<property name="ContactLastName">Johnson</property>
</object>
</data>
It works pretty well:
PHP Code:
<?xml version='1.0' encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:saxon2="http://saxon.sf.net/" >
<xsl:output method='xml' />
<xsl:variable name="modulename"><xsl:value-of select="//mappings/map[@name='module_name']" /></xsl:variable>
<xsl:variable name="lc_modulename"><xsl:value-of select="lower-case($modulename)" /></xsl:variable>
<xsl:variable name="crmondemand_namespace_xml">urn:/crmondemand/xml/<xsl:value-of select="$lc_modulename" /></xsl:variable>
<xsl:template match="/">
<data xmlns:n="urn:/crmondemand/xml/contact">
<xsl:variable name="ListOf">//n:ListOf<xsl:value-of select="$modulename" />/n:<xsl:value-of select="$modulename" /></xsl:variable>
<xsl:for-each select="saxon2:evaluate($ListOf)">
<object>
<xsl:for-each select="*">
<xsl:element name="property">
<xsl:attribute name="name">
<xsl:choose>
<xsl:when test="local-name()='IntegrationId'">replacewithidentifier</xsl:when>
<xsl:otherwise><xsl:value-of select="local-name()" /></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="." />
</xsl:element>
</xsl:for-each>
</object>
</xsl:for-each>
</data>
</xsl:template>
</xsl:stylesheet>
Now, instead of defining a concrete namespace in the data tag (<data xmlns:n="urn:/crmondemand/xml/contact">) I want to have a dynamic namespace (the content of the $crmondemand_namespace_xml variable).
How do I accomplish this?
Something like
PHP Code:
<data>
<xsl:namespace name="n" select="$crmondemand_namespace_xml" />
does not work.
Thank you very much in advance
