first step with iBatis
removing empty attributes
XSLT template to remove empty attributes from the xml.
<xsl:template match="/"> <xsl:copy> <xsl:apply-templates> <xsl:for-each select="@*"> <xsl:if test=".!=''"> <xsl:copy-of select="." /> </xsl:if> </xsl:for-each> </xsl:apply-templates> </xsl:copy> </xsl:template>
Sorting/Reordering elements using xslt
XSLT template to reorder the elements as per the position. The order option allows you to decide the order of sort. Depending on the select XPath query result data-type can be given.
<xsl:template match="*"> <xsl:copy> <xsl:apply-templates> <xsl:sort select="position()"order="descending" data-type="number" /> </xsl:apply-templates> </xsl:copy> </xsl:template>
copy elements using xslt
XSLT template to just copy all elements without any condition from one file to another.
<xsl:template match="* | @*"> <xsl:copy> <xsl:copy-of select="@*" /> <xsl:apply-templates /> </xsl:copy> </xsl:template>
xml to xml conversion using xslt
As I am new to XSLT wanted to perform some xsl transformation on my xml file and generate the xml. But when I were looking for some example how to do it I was getting all example who teach you how to transform an xml to html. So here is the way I found after some web search. Look at the tag <xsl:output> and its method just set it to xml as below. The code snippet to just copy all the elements and attributes from one xml file to another. If you want to perform some operations or checks you are free to add new templates.
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method='xml' indent='yes' /> <!-- copy all elements which don't match any template --> <xsl:template match="* | @*"> <xsl:copy> <xsl:copy-of select="@*" /> <xsl:apply-templates /> </xsl:copy> </xsl:template> </xsl:stylesheet>