Hi,
I previously posted under [xml copy with text substitution from map] and with
the help of folks here i got a working transform. However, I have discovered
one error. I am using a map to translates UIDs to text values, it works for
elements found in CDATA that have been decoded using saxon.parse() but
does not work for elements that were outside the CDATA.
I hope you can set me figure this out, it has been driving my crazy for 2 days.
Thanks in advance,
Tim
In the example below see: sEventDefinitionID (ouside CDATA) and
ENTITYTYPEID (inside CDATA) both have the same UID value.
From the Console output below I have verified the following:
The UID [
b02fb601b98a47ce8de32dbb157fb2a2] is in the map.
It doesn't have extra characters.
It is going thru the mapping template.
After passing thru the saxon.parse() the UID is correctly transformed to
POWER_FAILURE.
Console output:
Code:
PRE-MAP:raw-value: [b02fb601b98a47ce8de32dbb157fb2a2]
POST-MAP:[b02fb601b98a47ce8de32dbb157fb2a2]
PRE-MAP:raw-value: [b02fb601b98a47ce8de32dbb157fb2a2]
POST-MAP:[POWER_FAILURE]
Translated Ouput:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ReceivePanoramixEvents xmlns="http://eventreceiver.example.com/"
soap:EncodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sEventDefinitionID xsi:type="xsd:string">b02fb601b98a47ce8de32dbb157fb2a2</sEventDefinitionID>
<sXmlParameters>
<EVENT xmlns="">
<ENTITYTYPEID>POWER_FAILURE</ENTITYTYPEID>
</EVENT>
</sXmlParameters>
</ReceivePanoramixEvents>
</soap:Body>
</soap:Envelope>
Input Soap Msg (formatted for readability)
Code:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
>
<soap:Body>
<ReceivePanoramixEvents xmlns='http://eventreceiver.example.com/' soap:EncodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
<sEventDefinitionID xsi:type='xsd:string'>b02fb601b98a47ce8de32dbb157fb2a2</sEventDefinitionID>
<sXmlParameters xsi:type='xsd:string'><EVENT><ENTITYTYPEID>b02fb601b98a47ce8de32dbb157fb2a2</ENTITYTYPEID></EVENT>
</sXmlParameters>
</ReceivePanoramixEvents>
</soap:Body>
</soap:Envelope>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:saxon="http://saxon.sf.net/" xmlns:guid="java:com.me.pipe.dca.xyz.ConstantsMap" exclude-result-prefixes="saxon guid"
>
<!--
This transform is used to assist in debugging SOAP msgs.
These msgs contain CDATA, which I want to "un-escape" and
32 Char UID values which I need to translate to their text
equivalent. This is done for readability during debug.
-->
<!--
A Map (constantsXsltMap.xml) is used to translate between UIDs
and text values
<map>
<entry key="53bfdc0c8b9341688a520134b1098b26">VALUE_1</entry>
<entry key="73bfdc0c8b9341688a520134b1098b78">VALUE_2</entry>
<default>SOME_DEFAULT_VALUE</default>
</map>
-->
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:param name="map-file" select="string('constantsXsltMap.xml')" />
<xsl:variable name="map-doc" select="document($map-file)" />
<xsl:variable name="default" select="$map-doc/map/default[1]" />
<xsl:key name="map" match="/map/entry" use="@key" />
<!-- default copy transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- Identify element containing CDATA and perform and decode it -->
<xsl:template match="node()[ends-with(local-name(), 'sXmlParameters')]">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="saxon:parse(.)" />
</xsl:element>
</xsl:template>
<!-- Identify element containing CDATA and perform and decode it -->
<xsl:template match="node()[ends-with(local-name(), 'Result')]">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="saxon:parse(.)" />
</xsl:element>
</xsl:template>
<!--
Use contents of text element as Key value in map. If key is
found substitute with value, else leave as is
-->
<xsl:template match="*/text()">
<xsl:variable name="raw-value" select="." />
<xsl:message>PRE-MAP:raw-value: [<xsl:copy-of select="$raw-value"/>]</xsl:message>
<xsl:for-each select="$map-doc">
<xsl:value-of select="(key('map', $raw-value)|$raw-value)[1]" />
<xsl:message>POST-MAP:[<xsl:value-of select="(key('map', string($raw-value))|$raw-value)[1]"/>]</xsl:message>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>