Tuesday, 24 February 2015

Template placement in XSLT



I have an XSL which renames and extracts SOAPAction of incoming message. Both templates are working fine individually, but when combined, not working as expected. XSL template is simple renaming and copying the other message as it is. SOAPAction template uses datapower pre-defined variables(dp:) to extract SOAPAction Header into a local variable. The XSL written starts from the Envelopes Header match directly instead of a regular template match ="/". But my template down under is using (/)root match.In this case, where should be the SOAPAction template placed.


What is the correct way to keep above code in this XSL so that both my renaming of element and SOAPAction works.



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:ns="http://ift.tt/1DQtJjf" version="1.0"
extensions-element-prefixes="dp regexp"
xmlns:soapenv="http://ift.tt/sVJIaE"
xmlns:dp="http://ift.tt/1kRsgBO"
exclude-result-prefixes="dpfunc dpconfig"
xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:dpconfig="http://ift.tt/1qOCbsu">
<xsl:output omit-xml-declaration="yes" />

<xsl:template match="soapenv:Header">
<xsl:copy>
<!--Template for WSSE token exists here-->
<xsl:apply-templates />
</xsl:copy>

<!-- Template to perform a Standard Identity Transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>

<!--Template which renames a existing element-->
<xsl:template match="ns:Details">
<AddressDetails xmlns="http://ift.tt/1DQtJjf">
<UpdateAddressType>
<AddressPin>
<xsl:value-of select="ns:AddressPin" />
</AddressPin>
<AddressArea>
<xsl:value-of select="ns:AddressArea" />
</AddressArea>
</UpdateAddressType>
</AddressDetails>
</xsl:template>
<xsl:call-template name="HeaderChange" />
</xsl:template>

<xsl:template name="HeaderChange">
<xsl:variable select="dp:request-header('SOAPAction')" name="IncomingHeader" />
<xsl:message dp:priority="information">
<xsl:value-of select="$IncomingHeader" />
</xsl:message>
</xsl:template>
</xsl:stylesheet>


Sample XML:



<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://ift.tt/sVJIaE">
<s:Header />
<s:Body>
<MethodRequestType xmlns="http://ift.tt/1DQtJjf">
<MessageRequest xmlns:i="http://ift.tt/ra1lAU">
<ListRequest i:nil="true" />
<OptionsRequest i:nil="true" />
<PartyRequest>
<DemoHolder>
<Details>
<AddressPin></AddressArea>
</ContractType>
</Details>
</DemoHolder>
</PartyRequest>
</MessageRequest>
</MethodRequestType>
</s:Body>
</s:Envelope>

No comments:

Post a Comment