Showing posts with label how to. Show all posts
Showing posts with label how to. Show all posts

first step with iBatis

Posted at at 10:10 AM on Friday, December 10, 2010 by Posted by Ravindra Nikam | 0 comments   | Filed under: , , ,

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>

Posted at at 4:21 AM on Saturday, October 2, 2010 by Posted by Ravindra Nikam | 0 comments   | Filed under: , , ,

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>

Posted at at 6:03 AM on Friday, October 1, 2010 by Posted by Ravindra Nikam | 0 comments   | Filed under: , , ,

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>

Posted at at 5:57 AM on by Posted by Ravindra Nikam | 0 comments   | Filed under: , , ,

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>

Posted at at 6:19 AM on Thursday, September 30, 2010 by Posted by Ravindra Nikam | 0 comments   | Filed under: , , ,