Ticket #801: templates_sorter_2011_07_05.diff

File templates_sorter_2011_07_05.diff, 1.6 KB (added by fcxSanya, 13 years ago)
  • templatessorter/templatessorter.xsl

     
     1<xsl:stylesheet
     2  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     3  version="1.0">
     4
     5  <xsl:output indent="yes"/>
     6
     7  <xsl:template match="@* | node()">
     8    <xsl:copy>
     9      <xsl:apply-templates select="@* | node()"/>
     10    </xsl:copy>
     11  </xsl:template>
     12
     13  <!-- we use match="Entity" because we want to sort only top-level elements (contained in Entity) -->
     14  <xsl:template match="Entity">
     15    <xsl:copy>
     16      <xsl:apply-templates select="@*"/>
     17      <xsl:apply-templates select="*">
     18        <!-- with translate function sorting will be case-insensitive,
     19             because it will change lower-case letter to upper-case for sorting -->
     20        <xsl:sort select="translate(local-name(), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
     21      </xsl:apply-templates>
     22    </xsl:copy>
     23  </xsl:template>
     24
     25</xsl:stylesheet>
     26
  • templatessorter/templatessorter.sh

     
     1#!/bin/bash
     2# check arguments count
     3if [ $# -ne 1 ]; then
     4  echo 'usage: '$0' directory'
     5  exit
     6fi
     7# assign arguments to variables with readable names
     8input_directory=$1
     9# perform work
     10find $input_directory -name \*.xml -exec xsltproc -o {} templatessorter.xsl {} \;
     11