How can I remove brackets from payload in mule ESB? - replace

Currently I have a payload with brackets and with a , to separate each of the rows. The idea is to remove the [ at the beginning and the ] at the end, as well as , in the middle
Are there any idea?
[<?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>Not available. (30000,8)</DESCR2000><t_reserve_array class="R"><T_CPE_TYPE>SDSTB</T_CPE_TYPE><T_CPE_MODEL/><T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY></t_reserve_array><t_reserve_array class="R"><T_CPE_TYPE>SDSTB</T_CPE_TYPE><T_CPE_MODEL/><T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY></t_reserve_array></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>The Business Unit MARIO is not exist. (30000,4)</DESCR2000></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>The Business Unit ERNES is not exist. (30000,4)</DESCR2000></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>]

my comment is too long to be posted in comment section so rather posting here.
this is how your payload is looking.
[<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<reserveCPE_Res_Part>
<t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
<T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
<ORDER_NO/>
<DESCR2000>Not available. (30000,8)</DESCR2000>
<t_reserve_array class="R">
<T_CPE_TYPE>SDSTB</T_CPE_TYPE>
<T_CPE_MODEL/>
<T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
</t_reserve_array>
<t_reserve_array class="R">
<T_CPE_TYPE>SDSTB</T_CPE_TYPE>
<T_CPE_MODEL/>
<T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
</t_reserve_array>
</t_reserve_res>
</reserveCPE_Res_Part>
</reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<reserveCPE_Res_Part>
<t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
<T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
<ORDER_NO/>
<DESCR2000>The Business Unit MARIO is not exist. (30000,4)</DESCR2000>
</t_reserve_res>
</reserveCPE_Res_Part>
</reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<reserveCPE_Res_Part>
<t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
<T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
<ORDER_NO/>
<DESCR2000>The Business Unit ERNES is not exist. (30000,4)</DESCR2000>
</t_reserve_res>
</reserveCPE_Res_Part>
</reserveCPE_Res>]
after every comma there is a new xml that start, so you cannot embed multiple xml's under one xml unless what you are trying is to have multiple rows of data in xml.
the first thing that you want to do is to convert your input into a well-formed XML currently it is not. look at all these , <?xml version="1.0" encoding="UTF-8"?> in your payload makes it junk.
the following code will do what you are looking for
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<file:connector name="File" outputPattern="*" writeToDirectory="C:\Temp" readFromDirectory="C:\Users\satichen\Desktop\work\test" workDirectory="C:\Users\satichen\Desktop\saruku" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="playgroundFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value="#['[<?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>Not available. (30000,8)</DESCR2000><t_reserve_array class="R"><T_CPE_TYPE>SDSTB</T_CPE_TYPE><T_CPE_MODEL/><T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY></t_reserve_array><t_reserve_array class="R"><T_CPE_TYPE>SDSTB</T_CPE_TYPE><T_CPE_MODEL/><T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY></t_reserve_array></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>The Business Unit MARIO is not exist. (30000,4)</DESCR2000></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>The Business Unit ERNES is not exist. (30000,4)</DESCR2000></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>]']" mimeType="text/plain" doc:name="Set Payload"/>
<expression-component doc:name="remove quotes"><![CDATA[payload=payload.replace('[','');]]></expression-component>
<expression-component doc:name="remote quotes 2"><![CDATA[payload=payload.replace(']','');]]></expression-component>
<expression-component doc:name="Expression"><![CDATA[payload=payload.replace(',','');]]></expression-component>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
and produces the following output but as stated the output xml is still an invalid xml and you might want to revisit how your payload is actually getting formed at source and you might want to correct it.
<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<reserveCPE_Res_Part>
<t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
<T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
<ORDER_NO/>
<DESCR2000>Not available. (300008)</DESCR2000>
<t_reserve_array class="R">
<T_CPE_TYPE>SDSTB</T_CPE_TYPE>
<T_CPE_MODEL/>
<T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
</t_reserve_array>
<t_reserve_array class="R">
<T_CPE_TYPE>SDSTB</T_CPE_TYPE>
<T_CPE_MODEL/>
<T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
</t_reserve_array>
</t_reserve_res>
</reserveCPE_Res_Part>
</reserveCPE_Res>
<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<reserveCPE_Res_Part>
<t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
<T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
<ORDER_NO/>
<DESCR2000>The Business Unit MARIO is not exist. (300004)</DESCR2000>
</t_reserve_res>
</reserveCPE_Res_Part>
</reserveCPE_Res>
<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<reserveCPE_Res_Part>
<t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
<T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
<ORDER_NO/>
<DESCR2000>The Business Unit ERNES is not exist. (300004)</DESCR2000>
</t_reserve_res>
</reserveCPE_Res_Part>
</reserveCPE_Res>

Related

Extract XML Multiple Namespace with XSL

I have this XML with namespace and i need to extract on segment "NewDataSet"
I have a xsl code but it's not works
<?xml version="1.0" encoding="UTF-8"?>
<Listado_OrdenesResponse xmlns='http://tempuri.org/' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Listado_OrdenesResult>
<diffgr:diffgram xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
<NewDataSet xmlns=''>
<RowNum diffgr:id='RowNum1' msdata:rowOrder='0'>
<MATNR>10000101</MATNR> <AUFNR>731200000047</AUFNR>
<MENGE>385</MENGE>
<MEINS>G</MEINS>
</RowNum>
<RowNum diffgr:id='RowNum2' msdata:rowOrder='1'>
<MATNR>45000528</MATNR>
<AUFNR>731200000047</AUFNR>
<MENGE>540</MENGE>
<MEINS>KG</MEINS>
</RowNum>
</NewDataSet>
</diffgr:diffgram>
</Listado_OrdenesResult>
</Listado_OrdenesResponse>
I need to extract like this segment , NewDataSet.
<NewDataSet> <RowNum>
<MATNR>10000101</MATNR>
<AUFNR>731200000047</AUFNR>
</RowNum>
<RowNum>
<MATNR>45000528</MATNR>
<AUFNR>731200000047</AUFNR>
</RowNum>
</NewDataSet>
<!-- Need To Extract -->
I have this code but the return is not as expected.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2018 (https://www.liquid-technologies.com) -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="//NewDataSet">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
When I run the above XSL, I got this XML.
I will have the segment without namespace
<?xml version="1.0" encoding="UTF-8"?>
<RowNum xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
diffgr:id="RowNum1"
msdata:rowOrder="0">
<MATNR>10000101</MATNR>
<AUFNR>731200000047</AUFNR>
<MENGE>385</MENGE>
<MEINS>G</MEINS>
</RowNum>
<RowNum xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
diffgr:id="RowNum2"
msdata:rowOrder="1">
<MATNR>45000528</MATNR>
<AUFNR>731200000047</AUFNR>
<MENGE>540</MENGE>
<MEINS>KG</MEINS>
</RowNum>
Can you Help me?
In XSLT 2.0, use <xsl:copy-of select="XXXX" copy-namespaces='no'/>.
In XSLT 1.0 you need to use a variant of the identity template, copying elements using <xsl:element name="{local-name()}" namespace="namespace-uri()"/>.
Please don't ask XSLT questions without saying which version you are using, as many things are easier with XSLT 2.0 or 3.0!

XSLT transformation needed to add a SOAP envelope and split the XML between SOAP header and body

I have tried several options suggested in various blogs but would like to know if the following transformation is possible.
I need to convert the following XML,
<?xml version="1.0" encoding="UTF-8"?>
<ns1:ReturnLicensesForHost xmlns:ns1="http://example.com">
<ns1:userName>ABCDEFGH</ns1:userName>
<ns1:password>1234567</ns1:password>
<ns1:hostIdType>XYZ</ns1:hostIdType>
<ns1:hostId>987654</ns1:hostId>
<ns1:product>STUV</ns1:product>
</ns1:ReturnLicensesForHost>
into
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:fs="http://example.com">
<soap:Header>
<fs:Credentials>
<fs:userName>ABCDEFGH</fs:userName>
<fs:password>1234567</fs:password>
</fs:Credentials>
</soap:Header>
<soap:Body>
<fs:ReturnLicensesForHost>
<fs:hostIdType>XYZ</fs:hostIdType>
<fs:hostId>987654</fs:hostId>
<fs:product>STUV</fs:product>
</fs:ReturnLicensesForHost>
</soap:Body>
</soap:Envelope>
So basically, I need to add a SOAP envelope and split the fields across Header and Body.
Request your help with an XSLT for this transformation.
The conversion simply consists of putting the result XML in a template and replacing the desired values with xsl:value-of phrases referring to the input XML (including management of namespaces):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://example.com">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/ns1:ReturnLicensesForHost">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:fs="http://example.com">
<soap:Header>
<fs:Credentials>
<fs:userName><xsl:value-of select="ns1:userName" /></fs:userName>
<fs:password><xsl:value-of select="ns1:password" /></fs:password>
</fs:Credentials>
</soap:Header>
<soap:Body>
<fs:ReturnLicensesForHost>
<fs:hostIdType><xsl:value-of select="ns1:hostIdType" /></fs:hostIdType>
<fs:hostId><xsl:value-of select="ns1:hostId" /></fs:hostId>
<fs:product><xsl:value-of select="ns1:product" /></fs:product>
</fs:ReturnLicensesForHost>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:fs="http://example.com" xmlns:ns1="http://example.com">
<soap:Header>
<fs:Credentials>
<fs:userName>ABCDEFGH</fs:userName>
<fs:password>1234567</fs:password>
</fs:Credentials>
</soap:Header>
<soap:Body>
<fs:ReturnLicensesForHost>
<fs:hostIdType>XYZ</fs:hostIdType>
<fs:hostId>987654</fs:hostId>
<fs:product>STUV</fs:product>
</fs:ReturnLicensesForHost>
</soap:Body>
</soap:Envelope>

XSLT Help : Copy elements <choose>

With my limited knowledge of XSL programming I have come up with this code:
(Post updated: XSLT is now working - Updated for the benefit of others if at all!)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:nm="http://fsag.de/BusinessTransaction"
xmlns:env="http://www.w3.org/2001/12/soap-envelope"
exclude-result-prefixes="env">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/nm:Responses">
<xsl:copy-of select="/"/>
</xsl:template>
<xsl:template match="/Envelope">
<nm:Responses xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessages/>
<SystemContext/>
<Error>
<xsl:copy-of select="Body"/>
</Error>
</nm:Responses>
</xsl:template>
</xsl:stylesheet>
The purpose of the is to process the file (at the end of the post) and get the result below:
Required result for 'Error' file :
<?xml version="1.0" encoding="UTF-8"?>
<nm:Response xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessages/>
<SystemContext/>
<Error>
<Body>
<Response status="1">
<Description>DESC</Description>
<Errors>
<Error>500</Error>
</Errors>
</Response>
</Body>
</Error>
</nm:Response>
Required result for 'Response' file:
<?xml version="1.0" encoding="UTF-8"?>
<nm:Response xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessages>
<InOrderContext xmlns:n0="http://fsag.de/BusinessTransaction">
<SendTimestamp>01-06-2017:0506230000</SendTimestamp>
</InOrderContext>
<SystemContext>
<Client>FDP</Client>
<CorrelationId>34553FTG25543SFD134</CorrelationId>
<BusinessContext>RECONCL</BusinessContext>
</SystemContext>
</BTEMessages>
</nm:Response>
*File 1: Error *
<Envelope >
<Body>
<Response status="1">
<Description>DESC</Description>
<Errors>
<Error>500</Error>
</Errors>
</Response>
</Body>
</Envelope>
File 2: Response:
<?xml version="1.0" encoding="UTF-8"?>
<nm:Response xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessage>
<InOrderContext>
<SendTimestamp>01-06-2017:0506230000</SendTimestamp>
</InOrderContext>
<SystemContext>
<Client>FDP</Client>
<CorrelationId>34553FTG25543SFD134</CorrelationId>
<BusinessContext>RECONCL</BusinessContext>
</SystemContext>
</BTEMessage>
</nm:Response >
When i try to run the XSL is failing. Please any help here?
XSL updated with working version.

Removing xmlns, SOAP:Envelope, SOAP:Body, from xml using XSLT

I am using XSLT to transform the xml response in my project.I have the following xml.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP:Body>
<response:performJobResponse xmlns:response="http://tempuri.org/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<whiteboard>
<PQ>
<SOAP:Envelope SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP:Body>
<response:performJobResponse SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<whiteboard>
<PQ>
<SOAP:Envelope SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP:Body>
<performJob loadfromcache="yes">
<jobName>PQIssueUpdate</jobName>
<whiteboard>
<PQ>
<PQContact>
<userID>Test</userID>
<password>Test#2</password>
</PQContact>
<workflowStatusComment>
<comment>Issue released. Routing Status changed from CATCHALL to Pharmancy. Issue updated by user DT76747.</comment>
</workflowStatusComment>
</PQ>
</whiteboard>
<requestNodeName>//PQ</requestNodeName>
<responseNodeName>//PQ</responseNodeName>
<jobDB>
<name>PQCustomerService</name>
<userID>sa</userID>
<password>password</password>
</jobDB>
</performJob>
</SOAP:Body>
<response>
<DST xml:lang="en-US">
<jobName version="1.0">SRVChangeLock</jobName>
<trace>0</trace>
<readable>N</readable>
<AWD>
<userID>DT76747</userID>
<password>Removed for security purposes</password>
<transaction id="2016-07-07-02.02.19.127220T01">
<createTime time="Y">2016-07-07T02:02:19:127220-05:00</createTime>
<assignedTo>DT76747</assignedTo>
<lockedBy>DT76747</lockedBy>
<customScreen>WRKXMPL</customScreen>
<workflow route="Status">
<workStep status="_NEXT" next="Y" />
</workflow>
</transaction>
</AWD>
<jobVersion>1.0</jobVersion>
<jobReturn jobName="SRV00017">
<taskName />
<description />
<value>0</value>
</jobReturn>
</DST>
</response>
</SOAP:Envelope>
</PQ>
</whiteboard>
</response:performJobResponse>
</SOAP:Body>
<response>
<DST xml:lang="en-US">
<jobName version="1.0">SRVObjectUpdate</jobName>
<trace>0</trace>
<readable>N</readable>
<AWD>
<userID>DT76747</userID>
<password>Removed for security purposes</password>
<transaction id="2016-07-07-02.02.19.127220T01" workSelected="false" hasChildWork="N" children="N" hasParent="Y" hasParentCase="Y" hasChildSource="N">
<id>2016-07-07-02.02.19.127220T01</id>
</transaction>
</AWD>
</DST>
</response>
</SOAP:Envelope>
</PQ>
</whiteboard>
<jobReturn>
<value>0</value>
</jobReturn>
</response:performJobResponse>
</SOAP:Body>
</SOAP:Envelope>
I want to remove all the xmlns content,SOAP:Envelope, <SOAP:Body> and <response>tag related content.
My final xml should be as below:
<?xml version="1.0" encoding="UTF-8"?>
<PQ>
<PQContact>
<userID>Test</userID>
<password>Test#2</password>
</PQContact>
<workflowStatusComment>
<comment>Issue released. Routing Status changed from CATCHALL to Pharmancy. Issue updated by user DT76747.</comment>
</workflowStatusComment>
</PQ>
Could you please help me out?
Please, try this transformation:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:response="http://tempuri.org/">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="//SOAP:Body/performJob//whiteboard/node()"/>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="#*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>

One XML converted into multiple XML in Mule

I have one xml file like below.
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
Now I have to divide into 2 xmls having data like
1.xml
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
2.xml
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
This has to be completed in Mule. Please suggest the xslt in this case. I am a new guy in Mule.
The following flow should do what you asked for. You might need to do cleanup the namespaces if needed..
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<mulexml:xslt-transformer name="xslt">
<mulexml:xslt-text>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="">
<xsl:output method="xml"/>
<xsl:template match="/">
<machineDetail>
<xsl:copy-of select="." />
</machineDetail>
</xsl:template>
</xsl:stylesheet>
</mulexml:xslt-text>
</mulexml:xslt-transformer>
</mulexml:xslt-transformer>
<file:file-to-string-transformer name="File_to_String"
doc:name="File to String" />
<flow name="testflowsFlow">
<file:inbound-endpoint path="C:\Temp\mule\in"
responseTimeout="10000" doc:name="File" />
<file:file-to-string-transformer
doc:name="File to String" />
<splitter expression="#[xpath('//machineData')]" doc:name="Splitter"
enableCorrelation="ALWAYS" />
<mulexml:dom-to-xml-transformer
doc:name="DOM to XML" />
<file:outbound-endpoint transformer-refs="xslt"
path="C:\Temp\mule\out" responseTimeout="10000" doc:name="File"
outputPattern="#[message.outboundProperties.MULE_CORRELATION_SEQUENCE].xml" />
</flow>
Use a splitter in conjuction with an xpath MEL expression: like so:
<splitter expression="#[xpath('//machineDetail/machineData')]" doc:name="Splitter"/>
This will create two XML document like so:
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
Then while the message is split use XSLT or similar to wrap the XML in an
machineDetail element