Skip to content

Instantly share code, notes, and snippets.

@Madhuka
Last active August 15, 2018 13:10
Show Gist options
  • Save Madhuka/c982efb340c604405aec4f14d210e2ae to your computer and use it in GitHub Desktop.
Save Madhuka/c982efb340c604405aec4f14d210e2ae to your computer and use it in GitHub Desktop.
Basic XSLT
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" />
<xsl:template match="/">
<message>
<test>Company</test>
<xsl:for-each select="catalog/cd">
<compactDisc>
<discTitle>
<xsl:value-of select="title" />
</discTitle>
<artist>
<xsl:value-of select="artist" />
</artist>
<xsl:choose>
<xsl:when test="price &gt; 10">
<priceLevel>High</priceLevel>
</xsl:when>
<xsl:otherwise>
<priceLevel>Low</priceLevel>
</xsl:otherwise>
</xsl:choose>
</compactDisc>
</xsl:for-each>
</message>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes" />
<xsl:param name="date_time" />
<xsl:template match="/">
<output>
<input>
<xsl:value-of select="$date_time" />
</input>
<time-format type="test">
<xsl:value-of
select="format-dateTime(xs:dateTime($date_time), '[Y0001]/[M01]/[D01] [H01]:[m01]:[s01] [z]')" />
</time-format>
<required1 type="test1">
<xsl:value-of
select="format-dateTime(xs:dateTime($date_time), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')" />
</required1>
<required1 type="test2">
<xsl:value-of
select="format-dateTime(xs:dateTime($date_time), '[D] [MNn], [Y]')" />
</required1>
</output>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:output method="xml" indent="yes" />
<xsl:param name="date_time" />
<xsl:variable name="in" select="'30042013'" />
<xsl:variable name="month" select="substring($date_time,5,3)" />
<xsl:variable name="date_s1"
select="concat(
substring($date_time,25,4),'-')" />
<xsl:variable name="date_s2"
select="concat('-',
substring($date_time,9,2),'T',
substring($date_time,12,8))" />
<xsl:template match="/">
<output>
<input>
<xsl:value-of select="$date_time" />
</input>
<month>
<xsl:value-of select="$month" />
</month>
<monthNo>
<xsl:value-of select="$in" />
</monthNo>
<inputx>
<xsl:value-of select="$date_s1" />
<xsl:value-of select="$date_s2" />
</inputx>
<final>
<xsl:value-of select="$date_s1" />
<xsl:choose>
<xsl:when test="$month='Jan'">01</xsl:when>
<xsl:when test="$month='Feb'">02</xsl:when>
<xsl:when test="$month='Mar'">03</xsl:when>
<xsl:when test="$month='Apr'">04</xsl:when>
<xsl:when test="$month='May'">05</xsl:when>
<xsl:when test="$month='Jun'">06</xsl:when>
<xsl:when test="$month='Jul'">07</xsl:when>
<xsl:when test="$month='Aug'">08</xsl:when>
<xsl:when test="$month='Sep'">09</xsl:when>
<xsl:when test="$month='Oct'">10</xsl:when>
<xsl:when test="$month='Nov'">11</xsl:when>
<xsl:when test="$month='Dec'">12</xsl:when>
</xsl:choose>
<xsl:value-of select="$date_s2" />
</final>
</output>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<test>HelloWorld</test>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" />
<xsl:template match="/">
<message>
<test>Company</test>
<xsl:for-each select="catalog/cd">
<compactDisc>
<discTitle>
<xsl:value-of select="title" />
</discTitle>
<artist>
<xsl:value-of select="artist" />
</artist>
<xsl:if test="price &gt; 10">
<priceLevel>High</priceLevel>
</xsl:if>
</compactDisc>
</xsl:for-each>
</message>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<message>
<test>Company</test>
<xsl:for-each select="catalog/cd">
<compactDisc>
<discTitle><xsl:value-of select="title"/></discTitle>
<artist><xsl:value-of select="artist"/></artist>
</compactDisc>
</xsl:for-each>
</message>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" />
<xsl:template match="/">
<message>
<test>Company</test>
<xsl:for-each select="catalog/cd">
<xsl:sort select="title" />
<compactDisc>
<discTitle>
<xsl:value-of select="title" />
</discTitle>
<artist>
<xsl:value-of select="artist" />
</artist>
</compactDisc>
</xsl:for-each>
</message>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<property expression="//dateTime/original" name="originalFormat" scope="default" type="STRING"/>
<log description="log" level="custom">
<property name="message" value="test-api is hitted"/>
<property expression="$ctx:originalFormat" name="originalFormat"/>
</log>
<xslt key="gov:xslt/0.0.1/Date.xslt" source="//dateTime/output/type">
<property expression="$ctx:originalFormat" name="date_time"/>
</xslt>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<log description="log" level="custom">
<property name="message" value="test-api is hitted"/>
</log>
<xslt key="gov:xslt/0.0.1/HelloWorldX.xslt"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test1" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<property expression="//dateTime/original" name="originalFormat" scope="default" type="STRING"/>
<log level="custom">
<property name="Message" value="Testing API is hitted"/>
<property expression="$ctx:originalFormat" name="originalFormat"/>
</log>
<xslt key="gov:xslt/0.0.1/dateformater-xslt.xslt" source="//dateTime/original1">
<property expression="$ctx:originalFormat" name="date_time"/>
</xslt>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment