SlideShare a Scribd company logo
1 of 15
Mule XSLT
We often use XSLT in our application to transform XML
payload from one form to another . Mule also supports XSLT
in it’s application with XSLT-Transformer component.
So, How can we use XSLT in Mule application??
.
Here I will show you how ……
Before we start we must see what an XSLT actually is :-
As per XSLT definition :-
XSLT (Extensible Stylesheet Language Transformations) is a language
for transforming XML documents into other XML documents, or other
formats such as HTML for web pages, plain text or into XSL Formatting
Objects, which may subsequently be converted to other formats, such
as PDF PostScript and PNG.
Source :- http://en.wikipedia.org/wiki/XSLT
So, XSLT can be use to transform one form of XML to another :-
Here you can see the XSLT is transforming the XML payload into another XML
So, let us try this example in our Mule application
Here we will be using XSLT for transforming the XML payload into another XML
like below :-
So let’s consider we have a following flow in our Mule application:-
As you can see we have used a Http inbound end point followed by a set payload
component and then XSLT transformer.
Here the set payload contain the XML that need to be transform
So set payload component contains the following payload :-
Our corresponding Mule flow will be as follows :-
<flow name="xsltFlow1" doc:name="xsltFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081"
path="test" doc:name="HTTP"/>
<set-payload
value="&lt;RootElement&gt;&lt;Name&gt;Anirban&lt;/Name&gt;&lt;Department&gt;ATS&lt;/D
epartment&gt;&lt;Designation&gt;SSE&lt;/Designation&gt;&lt;/RootElement&gt;"
doc:name="Set Payload"/>
<mulexml:xslt-transformer
maxIdleTransformers="2" maxActiveTransformers="5" outputEncoding="UTF-8"
doc:name="Transform from outer to inner" xsl-file="Transform.xslt"
encoding="UTF-8" returnClass="java.lang.String" />
</flow>
As you can see we are using XSLT file :- Transform.xslt
So, the file Transform.xslt
should be in our src/main/resource folder
The file Transform.xslt
Contains following code to transform :-
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:template match="/">
<NewRootElement>
<NewName>
<xsl:value-of select="RootElement/Name" />
</NewName>
<NewDepartment>
<xsl:value-of select="RootElement/Department" />
</NewDepartment>
<NewDesignation>
<xsl:value-of select="RootElement/Designation" />
</NewDesignation>
</NewRootElement>
</xsl:template>
</xsl:stylesheet>
To test the application we hit the url http://localhost:8081/test in our
browser and we get the following :-
And you can see the XML payload has been transferred to this new XML
Hope you enjoyed the simple yet an amazing trick in Mule
Xslt in mule

More Related Content

What's hot

What's hot (13)

Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Mule Message Properties Component
Mule Message Properties ComponentMule Message Properties Component
Mule Message Properties Component
 
Xslt in mule
Xslt in muleXslt in mule
Xslt in mule
 
Mule requestor component
Mule requestor componentMule requestor component
Mule requestor component
 
Mule esb
Mule esbMule esb
Mule esb
 
Mule - HTTP Listener
Mule - HTTP ListenerMule - HTTP Listener
Mule - HTTP Listener
 
Mule esb transformers
Mule esb transformersMule esb transformers
Mule esb transformers
 
Idempotent filter with simple file
Idempotent filter with simple fileIdempotent filter with simple file
Idempotent filter with simple file
 
Mule Webservices
Mule WebservicesMule Webservices
Mule Webservices
 
Using XSLT in Mule
Using XSLT in MuleUsing XSLT in Mule
Using XSLT in Mule
 
File component in mule
File component in muleFile component in mule
File component in mule
 
Mule with composite source
Mule with composite sourceMule with composite source
Mule with composite source
 
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esbSend email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
 

Viewers also liked

Efecto multiplicador bancario y encajes
Efecto multiplicador bancario y encajesEfecto multiplicador bancario y encajes
Efecto multiplicador bancario y encajesemmanuelpocovi
 
Gate 2016 S1 exam paper
Gate 2016 S1 exam paperGate 2016 S1 exam paper
Gate 2016 S1 exam paperJoy Dey
 
Validate soap request in mule
Validate soap request in muleValidate soap request in mule
Validate soap request in muleHasan Syed
 
INTERCORP presentation_UPDATE 13_01
INTERCORP presentation_UPDATE 13_01INTERCORP presentation_UPDATE 13_01
INTERCORP presentation_UPDATE 13_01Marina Bay
 
Mule with drools
Mule with droolsMule with drools
Mule with droolsHasan Syed
 
Comercio electrónico
Comercio electrónicoComercio electrónico
Comercio electrónicoCAROLINA HDZ
 
Oracle Partner Certification
Oracle Partner CertificationOracle Partner Certification
Oracle Partner Certificationfongdun huang
 

Viewers also liked (16)

Efecto multiplicador bancario y encajes
Efecto multiplicador bancario y encajesEfecto multiplicador bancario y encajes
Efecto multiplicador bancario y encajes
 
tarek.cv2016
tarek.cv2016tarek.cv2016
tarek.cv2016
 
Fault tolerance
Fault toleranceFault tolerance
Fault tolerance
 
Gate 2016 S1 exam paper
Gate 2016 S1 exam paperGate 2016 S1 exam paper
Gate 2016 S1 exam paper
 
Validate soap request in mule
Validate soap request in muleValidate soap request in mule
Validate soap request in mule
 
INTERCORP presentation_UPDATE 13_01
INTERCORP presentation_UPDATE 13_01INTERCORP presentation_UPDATE 13_01
INTERCORP presentation_UPDATE 13_01
 
Uso de la b, v
Uso de la b, vUso de la b, v
Uso de la b, v
 
Harbin Dadi E-catalog
Harbin Dadi E-catalog Harbin Dadi E-catalog
Harbin Dadi E-catalog
 
Jenkins2
Jenkins2Jenkins2
Jenkins2
 
Mule with drools
Mule with droolsMule with drools
Mule with drools
 
KIR February Progress Report
KIR February Progress ReportKIR February Progress Report
KIR February Progress Report
 
The Joke is on You
The Joke is on YouThe Joke is on You
The Joke is on You
 
Proyecto final
Proyecto finalProyecto final
Proyecto final
 
Comercio electrónico
Comercio electrónicoComercio electrónico
Comercio electrónico
 
Oracle Partner Certification
Oracle Partner CertificationOracle Partner Certification
Oracle Partner Certification
 
4_MARCH
4_MARCH4_MARCH
4_MARCH
 

Similar to Xslt in mule

Using xslt in mule
Using xslt in mule Using xslt in mule
Using xslt in mule javeed_mhd
 
Using xslt in mule
Using xslt in mule Using xslt in mule
Using xslt in mule mdfkhan625
 
Using xslt in mule
Using xslt in mule Using xslt in mule
Using xslt in mule Rajkattamuri
 
Using xslt in mule
Using  xslt in muleUsing  xslt in mule
Using xslt in muleKhan625
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mulejaveed_mhd
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in muleMohammed625
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mulemdfkhan625
 
Xml to xml transformation
Xml to xml transformationXml to xml transformation
Xml to xml transformationSon Nguyen
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in muleGermano Barba
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in muleDavide Rapacciuolo
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in muleDavide Rapacciuolo
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesbGermano Barba
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHPStephan Schmidt
 

Similar to Xslt in mule (20)

Using xslt in mule
Using xslt in mule Using xslt in mule
Using xslt in mule
 
Using xslt in mule
Using xslt in mule Using xslt in mule
Using xslt in mule
 
Using xslt in mule
Using xslt in mule Using xslt in mule
Using xslt in mule
 
Using xslt in mule
Using  xslt in muleUsing  xslt in mule
Using xslt in mule
 
Using xslt in mule
Using xslt in mule Using xslt in mule
Using xslt in mule
 
Xml transform
Xml transformXml transform
Xml transform
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation
Xml to xml transformationXml to xml transformation
Xml to xml transformation
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Xml toobjectesbtransform
Xml toobjectesbtransformXml toobjectesbtransform
Xml toobjectesbtransform
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
XSLT
XSLTXSLT
XSLT
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
 

More from Hasan Syed

Web service vm in mule
Web service vm in muleWeb service vm in mule
Web service vm in muleHasan Syed
 
Simple web service vm
Simple web service vmSimple web service vm
Simple web service vmHasan Syed
 
Scatter gather flow control
Scatter gather flow controlScatter gather flow control
Scatter gather flow controlHasan Syed
 
Mule with velocity
Mule with velocityMule with velocity
Mule with velocityHasan Syed
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mqHasan Syed
 
Mule with quartz
Mule with quartzMule with quartz
Mule with quartzHasan Syed
 
Idempotent filter with simple file
Idempotent filter with simple fileIdempotent filter with simple file
Idempotent filter with simple fileHasan Syed
 
Groovy with mule
Groovy with muleGroovy with mule
Groovy with muleHasan Syed
 
Creating dynamic json
Creating dynamic jsonCreating dynamic json
Creating dynamic jsonHasan Syed
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformerHasan Syed
 
Caching and invalidating with managed store
Caching and invalidating with managed storeCaching and invalidating with managed store
Caching and invalidating with managed storeHasan Syed
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community editionHasan Syed
 
Automatic documentation with mule
Automatic documentation with muleAutomatic documentation with mule
Automatic documentation with muleHasan Syed
 

More from Hasan Syed (19)

Web service vm in mule
Web service vm in muleWeb service vm in mule
Web service vm in mule
 
Simple web service vm
Simple web service vmSimple web service vm
Simple web service vm
 
Scatter gather flow control
Scatter gather flow controlScatter gather flow control
Scatter gather flow control
 
Mule with velocity
Mule with velocityMule with velocity
Mule with velocity
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mq
 
Mule with quartz
Mule with quartzMule with quartz
Mule with quartz
 
Mule esb
Mule esbMule esb
Mule esb
 
Maven iii
Maven iiiMaven iii
Maven iii
 
Maven ii
Maven iiMaven ii
Maven ii
 
Maven part 1
Maven part 1Maven part 1
Maven part 1
 
Jenkins3
Jenkins3Jenkins3
Jenkins3
 
Jenkins
JenkinsJenkins
Jenkins
 
Idempotent filter with simple file
Idempotent filter with simple fileIdempotent filter with simple file
Idempotent filter with simple file
 
Groovy with mule
Groovy with muleGroovy with mule
Groovy with mule
 
Creating dynamic json
Creating dynamic jsonCreating dynamic json
Creating dynamic json
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformer
 
Caching and invalidating with managed store
Caching and invalidating with managed storeCaching and invalidating with managed store
Caching and invalidating with managed store
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community edition
 
Automatic documentation with mule
Automatic documentation with muleAutomatic documentation with mule
Automatic documentation with mule
 

Recently uploaded

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Xslt in mule

  • 2. We often use XSLT in our application to transform XML payload from one form to another . Mule also supports XSLT in it’s application with XSLT-Transformer component.
  • 3. So, How can we use XSLT in Mule application?? .
  • 4. Here I will show you how ……
  • 5. Before we start we must see what an XSLT actually is :- As per XSLT definition :- XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or into XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF PostScript and PNG. Source :- http://en.wikipedia.org/wiki/XSLT
  • 6. So, XSLT can be use to transform one form of XML to another :- Here you can see the XSLT is transforming the XML payload into another XML
  • 7. So, let us try this example in our Mule application Here we will be using XSLT for transforming the XML payload into another XML like below :-
  • 8. So let’s consider we have a following flow in our Mule application:- As you can see we have used a Http inbound end point followed by a set payload component and then XSLT transformer. Here the set payload contain the XML that need to be transform
  • 9. So set payload component contains the following payload :-
  • 10. Our corresponding Mule flow will be as follows :- <flow name="xsltFlow1" doc:name="xsltFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="test" doc:name="HTTP"/> <set-payload value="&lt;RootElement&gt;&lt;Name&gt;Anirban&lt;/Name&gt;&lt;Department&gt;ATS&lt;/D epartment&gt;&lt;Designation&gt;SSE&lt;/Designation&gt;&lt;/RootElement&gt;" doc:name="Set Payload"/> <mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" outputEncoding="UTF-8" doc:name="Transform from outer to inner" xsl-file="Transform.xslt" encoding="UTF-8" returnClass="java.lang.String" /> </flow> As you can see we are using XSLT file :- Transform.xslt
  • 11. So, the file Transform.xslt should be in our src/main/resource folder
  • 12. The file Transform.xslt Contains following code to transform :- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes" /> <xsl:template match="/"> <NewRootElement> <NewName> <xsl:value-of select="RootElement/Name" /> </NewName> <NewDepartment> <xsl:value-of select="RootElement/Department" /> </NewDepartment> <NewDesignation> <xsl:value-of select="RootElement/Designation" /> </NewDesignation> </NewRootElement> </xsl:template> </xsl:stylesheet>
  • 13. To test the application we hit the url http://localhost:8081/test in our browser and we get the following :- And you can see the XML payload has been transferred to this new XML
  • 14. Hope you enjoyed the simple yet an amazing trick in Mule