Reputation: 125
I am construction a message using BizTalk Map and applying external XSLT to it. I want the transformed XML to be having '<' and '>' instead of "<" and ">" for example:
My Input XML is:
<DEALER>
<DEALER_DETAILS>
<ID>DL00005</ID>
<DEALER_NAME>Dealer Name</DEALER_NAME>
<INN_NUMBER>7736530296</INN_NUMBER>
<KPP_NUMBER>773601001</KPP_NUMBER>
<OKPO_NUMBER>69076838</OKPO_NUMBER>
<SAP_CODE>SAP101</SAP_CODE>
<UPDATE_DATE>2010-08-02</UPDATE_DATE>
</DEALER_DETAILS>
</DEALER>
XSLT that I am applying is:
<xsl:template match="/">
<xsl:apply-templates select="/DEALER" />
</xsl:template>
<xsl:template match="/DEALER">
<Result>
<Dealer>
<xsl:copy-of select="/*" />
</Dealer>
</Result>
</xsl:template>
Output is:
<Result>
<DEALER xmlns="http://tempuri.org/RSINT9_Output.xsd">
<DEALER_DETAILS>
<ID>DL00005</ID>
<DEALER_NAME>Dealer Name Again</DEALER_NAME>
<INN_NUMBER>7736530296</INN_NUMBER>
<KPP_NUMBER>773601001</KPP_NUMBER>
<OKPO_NUMBER>69076838</OKPO_NUMBER>
<SAP_CODE>SAP101</SAP_CODE>
<UPDATE_DATE>2010-08-02</UPDATE_DATE>
</DEALER_DETAILS>
</DEALER>
</Result>
But I want the output to be like :
<Result>
<DEALER xmlns="http://tempuri.org/RSINT9_Output.xsd">
<DEALER_DETAILS>
<ID>DL00005</ID>
<DEALER_NAME>Dealer Name Again</DEALER_NAME>
<INN_NUMBER>7736530296</INN_NUMBER>
<KPP_NUMBER>773601001</KPP_NUMBER>
<OKPO_NUMBER>69076838</OKPO_NUMBER>
<SAP_CODE>SAP101</SAP_CODE>
<UPDATE_DATE>2010-08-02</UPDATE_DATE>
</DEALER_DETAILS>
</DEALER>
</Result>
Please guide me.
Thanks, Mayur Jadhav
Upvotes: 2
Views: 1228
Reputation: 107237
This should do the trick - it works by capturing the result of your XSLT transform into a variable, and then using C# script to grab the XmlEncoded OuterXml.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="userCSharp msxsl"
>
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<!--Capture the result of the XSLT Transform into a variable-->
<xsl:variable name="xmlTree">
<xsl:call-template name="CreateXml">
</xsl:call-template>
</xsl:variable>
<!--Use a C# function to 'escape' the XML-->
<xsl:value-of select="userCSharp:EscapeXml($xmlTree)"/>
</xsl:template>
<!--Do your transform here, using XSLT, Functoids, etc-->
<xsl:template name="CreateXml">
<Result>
<xsl:copy-of select="/*" />
</Result>
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp">
<![CDATA[
// Escape the outer Xml
public System.String EscapeXml(System.Xml.XPath.XPathNavigator x)
{
return x.OuterXml;
}
]]>
</msxsl:script>
</xsl:stylesheet>
Upvotes: 3