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: , , ,