Saturday, January 8, 2011

XSLT transformation and Line Breaks

This post details how to add and remove Line Breaks in a XSLT.

Removing Line Breaks in XSLT:

Consider the XML below. Need to remove the line breaks in the input payload:
<test>Line1
Line2</test>


Use the XSLT chunk below to remove the line break from the XML:
<xsl:variable name="Temp">
<xsl:value-of select="translate(/InputXml/test, '&#xA;', '|')"/>
</xsl:variable>
<Line1>
<xsl:value-of select="substring-before($Temp,'|')"/>
</Line1>
<Line2>
<xsl:value-of select="substring-after($Temp,'|')"/>
</Line2>


And then do a concat($Line1,',',$Line2) or as required!

Adding Line Breaks in XSLT:

Adding a line break should not be an issue once the removal of it has been figured out. Lets consider the same XML without line break. We will add line breaks to generate the xml:
<test>Line1
Line2</test>


 Use the XSLT chunk below to add the line break from the XML:
<xsl:stylesheet version="1.0">
<xsl:template match="/">
<OutputXml>
<Details>
<xsl:value-of select="concat(/InputXml/Line1,'&#xA;',/InputXml/Line2)"/>
</Details>
</OutputXml>
</xsl:template>
</xsl:stylesheet>
 

Cheers,
-AR
 

1 comment:

Ajral said...

Hi Arun,

I am dealing with a scenario where i have to interact with some web service which entertain XML argument input and return XML output only,(my service is on weblogic and the service which i am trying to call is on glassfish)
----------------------------------------------------------------------------------------------------------------------------------------------
example:- my BPEL's inputs and outputs corresponding webservice inputs and outputs are like.

@ BPEL input and outputs
---------------------------------------------
*Input to my BPEL-->>
request ---username type "string"
---password type "string"


*output from my BPEL-->>
response ---status type=" string"
---code type ="string"



@ the webservice which i am trying to call: input and outputs

inputXML


outputXML
----------------------------------------------------------------------------------------------------------------------------------------------
the reference side have only one input i.e input XML.. and also after successful login it should give out the response in such a format so that my BPEL can interact with that so until and unless i did not found a solution to convert my input to the BPEL (input xsd) to XML i will not able to do so .I have tried the following -- Using the XPath function-- ora:parseEscapedXML() to take an XML string and convert it to DOM format for processing in BPEL but getting Xpath error. Please Please help me out if you have any solutions.

#Secondly
To escape the above deadlock we place a wrapper layer between both the service my services are running on weblogic and the service which i am trying to call is on glassfish ,with this approach we are Successfully hitting the service but not getting any response but instead getting error-----"error getting response;java.net.SocketTimeoutException:Read timed in weblogic" please help me out if you have any solutions..

Thanks and Regards
Abhishek Ajral

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License