Hi team,

I have requirement to replace 
 character and replace it with \n using
XSLT. So I came up with following XSLT and Proxy service. ( Capp is
attached )

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"; xmlns:tns="
http://www.example.org/Echo/";>
    <xsl:output method="text" encoding="UTF-8" indent="yes"/>
    <xsl:template name="escapeNewLine">
        <xsl:param name="text" select="string(.)"/>
        <xsl:choose>
            <xsl:when test="contains($text, '&#xA;')">
                <xsl:value-of select="substring-before($text,
'&#xA;')"/>\n<xsl:call-template name="escapeNewLine">
                    <xsl:with-param name="text"
select="substring-after($text, '&#xA;')"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$text"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="/"><tns:echoOut xmlns:tns="
http://www.example.org/Echo/";><out><xsl:call-template name="escapeNewLine">
            <xsl:with-param name="text" select="."/>
        </xsl:call-template></out></tns:echoOut>
    </xsl:template>
</xsl:stylesheet>

*And Proxy : *

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"; name="TestXSLT"
transports="http https" startOnLoad="true" trace="disable">
    <target>
        <inSequence>
            <xslt key="conf:xslt/Test.xslt" source="//in"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
    <publishWSDL key="conf:xslt/Echo.wsdl"/>
</proxy>


In above transformation, it replace all the space with \n. For following
request.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:echo="http://www.example.org/Echo/";>
   <soapenv:Header/>
   <soapenv:Body>
      <echo:echo>
         <in>a b
         c d
         </in>
      </echo:echo>
   </soapenv:Body>
</soapenv:Envelope>

Response will be like this.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:echo="http://www.example.org/Echo/";>
   <soapenv:Body>
      <echo:echo>
         <text xmlns="http://ws.apache.org/commons/ns/payload";>a\nb
\n\n\n\n\n\n\n\n\nc\nd
\n\n\n\n\n\n\n\n\n</text>
      </echo:echo>
   </soapenv:Body>
</soapenv:Envelope>

What could be the issue. ? I tried with both &amp;#xA; and &#xA still no
luck.

Thanks,
Hasitha.

-- 
Hasitha Aravinda,
Software Engineer,
WSO2 Inc.
Email: hasi...@wso2.com
Mobile: +94 71 8 210 200

Attachment: TestXSLTCapp_1.0.0.car
Description: Binary data

_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to