1
0
forked from 0ad/0ad

Templates sorting utility. Closes #801.

This was SVN commit r9938.
This commit is contained in:
fcxSanya 2011-07-30 20:20:34 +00:00
parent 328d33b9e9
commit 3cc1c7e24e
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Templates sorting utility aimed to sort components (second level xml elements) in simulation templates in alphabetical order.
Usage:
./templatessorter.sh path_to_folder_with_simulation_templates

View File

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

View File

@ -0,0 +1,26 @@
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output encoding="utf-8" indent="yes"/>
<xsl:template match="@* | node() | comment()">
<xsl:copy>
<xsl:apply-templates select="@* | node() | comment()"/>
</xsl:copy>
</xsl:template>
<!-- we use match="/Entity" because we want to sort only second-level elements (contained in top level Entity) -->
<xsl:template match="/Entity">
<xsl:copy>
<xsl:apply-templates select="@* | comment()"/>
<xsl:apply-templates select="*">
<!-- with translate function sorting will be case-insensitive,
because it will change lower-case letter to upper-case for sorting -->
<xsl:sort select="translate(local-name(), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>