parent
328d33b9e9
commit
3cc1c7e24e
5
source/tools/templatessorter/readme.txt
Normal file
5
source/tools/templatessorter/readme.txt
Normal 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
|
||||
|
11
source/tools/templatessorter/templatessorter.sh
Normal file
11
source/tools/templatessorter/templatessorter.sh
Normal 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 {} \;
|
||||
|
26
source/tools/templatessorter/templatessorter.xsl
Normal file
26
source/tools/templatessorter/templatessorter.xsl
Normal 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>
|
||||
|
Loading…
Reference in New Issue
Block a user