BizTalk Map - Xslt Issue

Hi,

Here is a piece of xslt, i need to replace the characters with their shortcode which are not supported in xml.

For eg i need to replace '&' to '&amp' and similarly all other characters as mentioned

Unsupported characters and their replacements:

& - &
< - &lt;
> - &gt;
" - &quot;
' - &#39;

XSLT:

<xsl:if test="/*[local-name()='Root' and namespace-uri()='http://schemas.microsoft.com/BizTalk/2003/aggschema']/*[local-name()='InputMessagePart_1' and namespace-uri()='']/*[local-name()='GetOrderDetailsByIdResponse' and namespace-uri()='http://tempuri.org/']/*[local-name()='GetOrderDetailsByIdResult' and namespace-uri()='http://tempuri.org/']/*[local-name()='TermsAndConditionList' and namespace-uri()='http://schemas.datacontract.org/2004/07/GEP.Cumulus.P2P.BusinessEntities']/*[local-name()='TermsAndCondition' and namespace-uri()='http://schemas.datacontract.org/2004/07/Gep.Cumulus.CSM.Entities']/*[local-name()='TermsConditionText' and namespace-uri()='http://schemas.datacontract.org/2004/07/Gep.Cumulus.CSM.Entities']/text()">
<Extrinsic>
<HeaderExtrinsic>
<TermsAndConditions>
<xsl:for-each select="../s10:TermsAndConditionList">
<xsl:for-each select="s9:TermsAndCondition">
<xsl:if test="s9:TermsConditionText">
<TermsAndCondition>
<xsl:value-of select="s9:TermsConditionText/text()" /> 
</TermsAndCondition>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</TermsAndConditions>
</HeaderExtrinsic>
</Extrinsic>
</xsl:if>

[Need to do it in the value coming from termandcondition text ie s9:TermsConditionText]

Thanks in Advance

February 6th, 2015 2:50pm

Are you sure that you need to do this?

XSLT input is always XML, and in your input XML these special characters should already be encoded, otherwise the input XML would not be valid in the first place.

Can you show a sample input where an element contains text with a special char that is not encoded?

Morten la Cour

Free Windows Admin Tool Kit Click here and download it now
February 6th, 2015 3:01pm

You can do this by disabling output encoding in the custom xsl like  this 'disable-output-escaping="yes"'.

BUt you would not be able to validate the xml.

February 6th, 2015 3:05pm

But the problem here is ,in the input schema is made according to the service structure and in service the value would be fetched from db where in this un supported characters can occur. So that is the reason i am doing it to avoid the parsing error while transformation when this characters will occur.

Please help.

Thanks in advance

Free Windows Admin Tool Kit Click here and download it now
February 6th, 2015 3:19pm

But still, when you fetch the data (from at DB Adapter I take it)? the Adapter will create the input XML for you, and automatically encode the illegal characters. Do you have an input sample where the characters are not encoded?

Morten la Cour

February 6th, 2015 3:24pm

  <ns5:TermsConditionText>Terms&conditions</ns5:TermsConditionText>
            <ns5:UpdatedByName>User1</ns5:UpdatedByName>
          </ns5:TermsAndCondition>

Here is the sample i got from the service xml

Free Windows Admin Tool Kit Click here and download it now
February 6th, 2015 3:47pm

Then go back to the source and explain to them that this is not valid XML, and you cannot consume it. Have you tried opening this XML in a web browser? or have an XML Disassemble Pipeline Component consume it?

It should be 

<ns5:TermsConditionText>Terms&amp;conditions</ns5:TermsConditionText>

From the source, otherwise you will not be able to parse it as XML.

Morten la Cour

February 6th, 2015 3:52pm

Then go back to the source and explain to them that this is not valid XML, and you cannot consume it. Have you tried opening this XML in a web browser? or have an XML Disassemble Pipeline Component consume it?

It should be 

<ns5:TermsConditionText>Terms&amp;conditions</ns5:TermsConditionText>

From the source, otherwise you will not be able to parse it as XML.

Morten la Cour

Free Windows Admin Tool Kit Click here and download it now
February 6th, 2015 3:52pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics