# File that produces shorter names
# Variables for attribute values and elements
$avalue=[^"]*;
$element=[a-zA-Z0-9]+;

# Complete noise
'//ldml' > ;

# First codes list
'/localeDisplayNames/languages/' ($element) '[@type="' ($avalue) '"]' > '0-names|' $1 '|' $2;
'/localeDisplayNames/scripts/' ($element) '[@type="' ($avalue) '"]' > '0-names|' $1 '|' $2;
'/localeDisplayNames/territories/' ($element) '[@type="' ($avalue) '"]' > '0-names|' $1 '|' $2;
'/localeDisplayNames/variants/' ($element) '[@type="' ($avalue) '"]' > '0-names|' $1 '|' $2;
'/localeDisplayNames/keys/' ($element) '[@type="' ($avalue) '"]' > '0-names|type|' $2;
'/localeDisplayNames/types/' ($element) '[@type="' ($avalue) '"]'  '[@key="' ($avalue) '"]' > '0-names|' $1 '|' $3 '-' $2;
'/localeDisplayNames/codePatterns/' ($element) '[@type="' ($avalue) '"]' > '0-names|' $1 '|' $2;
'/localeDisplayNames/localeDisplayPattern/' ($element) > '0-names|localeDisplayPattern|' $1;
'/localeDisplayNames/transformNames/transformName[@type="' ($avalue) '"]' > '0-names|transforms|' $1;

'/localeDisplayNames/languages/alias' > '0-names|language|alias';
'/localeDisplayNames/territories/alias' > '0-names|territory|alias';

'/layout/orientation' > '1-misc|layout|orientation';

'/contextTransforms/contextTransformUsage[@type="' ($avalue) '"]/contextTransform[@type="' ($avalue) '"]' > '1-misc|contextTransforms|' $1 '/' $2;
'/contextTransforms/contextTransformUsage[@type="' ($avalue) '"]/alias' > '1-misc|contextTransforms|$1-alias';

'/characters/exemplarCharacters[@type="index"]' > '1-misc|indexCharacters|';
'/characters/exemplarCharacters[@type="' ($avalue) '"]' > '1-misc|exemplarCharacters|2-' $1;
'/characters/exemplarCharacters' > '1-misc|exemplarCharacters|2-main';

'/characters/stopwords/stopwordList[@type="' ($avalue) '"]' > '1-misc|stopwords|' $1;

'/characters/indexLabels/indexLabel[@indexSource="' ($avalue) '"]' > '1-misc|indexLabels|label-' $1;
'/characters/indexLabels/' ($element) > '1-misc|indexLabels|' $1;

'/characters/ellipsis[@type="' ($avalue) '"]' > '1-misc|ellipsisPatterns|' $1;
'/characters/moreInformation' > '1-misc|information|symbol';

'/listPatterns/listPattern/listPatternPart[@type="' ($avalue) '"]' > '1-misc|listPattern|' $1;

'/delimiters/'(.*) > '1-misc|delimiters|' $1;
'/fallback' > '1-misc|fallback|locales' ;

# catch defaults:
# //ldml/dates/calendars/calendar[@type="buddhist"]/X/default

'/dates/calendars/default' > '3-deprecated|default|calendar';
'/dates/calendars/calendar[@type="' ($avalue) '"]/' ($element) '/default' > '3-deprecated|default|calendar-' $1 '-' $2;
'/dates/localizedPatternChars' > '3-deprecated|dates|localizedPatternChars';
# '$%%/dateTimeFormats/default' > '3-deprecated|default|date+time|default';

# The $%% is used to break up the transformation into two chunks, for modularization

#'/dates/calendars/calendar[@type="' 'gregorian' '"]' > 'calendar-' | '$%%';
'/dates/calendars/calendar[@type="' ($avalue) '"]' > 'calendar-' $1 | '$%%';

'/identity/' ($element) '[@type="' ($avalue) '"]' > 'identity|' $1 '|' $2;
'/identity/' ($element) > 'identity|info|' $1;
# /identity/generation
# identity|info|territory?%%[@type="DJ"]

'/localeDisplayNames/measurementSystemNames/measurementSystemName[@type="' ($avalue) '"]' > '0-names|measurement-system|' $1;
'/references/reference[@type="' ($avalue) '"]' > 'references|reference|' $1;

'$%%/eras/era' ($element) '/era[@type="' ([0-9]) '"]' > '|era|[00' $2 ']-' $1;
'$%%/eras/era' ($element) '/era[@type="' ([0-9][0-9]) '"]' > '|era|[0' $2 ']-' $1;
'$%%/eras/era' ($element) '/era[@type="' ($avalue) '"]' > '|era|[' $2 ']-' $1;

'$%%/dateFormats/dateFormatLength[@type="' ($avalue) '"]/dateFormat[@type="standard"]/pattern[@type="standard"]' > '|pattern|date-' $1;
'$%%/timeFormats/timeFormatLength[@type="' ($avalue) '"]/timeFormat[@type="standard"]/pattern[@type="standard"]' > '|pattern|time-' $1;
'$%%/dateTimeFormats/dateTimeFormatLength[@type="' ($avalue) '"]/dateTimeFormat[@type="standard"]/pattern[@type="standard"]' > '|pattern|datetime-' $1;

'$%%/months/monthContext[@type="' ($avalue) '"]/monthWidth[@type="' ($avalue) '"]/month[@type="' ([0-9]) '"][@yeartype="leap"]' > '|month|[0' $3 ']-' $1 '-' $2 '-leap';
'$%%/months/monthContext[@type="' ($avalue) '"]/monthWidth[@type="' ($avalue) '"]/month[@type="' ($avalue) '"][@yeartype="leap"]' > '|month|[' $3 ']-' $1 '-' $2 '-leap';

'$%%/months/monthContext[@type="' ($avalue) '"]/monthWidth[@type="' ($avalue) '"]/month[@type="' ([0-9]) '"]' > '|month|[0' $3 ']-' $1 '-' $2;
'$%%/months/monthContext[@type="' ($avalue) '"]/monthWidth[@type="' ($avalue) '"]/month[@type="' ($avalue) '"]' > '|month|[' $3 ']-' $1 '-' $2;
'$%%/months/monthContext[@type="' ($avalue) '"]/monthWidth[@type="' ($avalue) '"]/alias' > '|month|' $1 '-' $2 '-alias';

'$%%/monthPatterns/monthPatternContext[@type="' ($avalue) '"]/monthPatternWidth[@type="' ($avalue) '"]/monthPattern[@type="' ($avalue) '"]' > '|monthPattern|[' $3 ']-' $1 '-' $2;
'$%%/monthPatterns/monthPatternContext[@type="' ($avalue) '"]/monthPatternWidth[@type="' ($avalue) '"]/alias' > '|monthPattern|' $1 '-' $2 '-alias';

'$%%/months/monthContext[@type="' ($element) '"]/default' > '|month|default-' $1;
'$%%/days/dayContext[@type="' ($element) '"]/default' > '|day|default-' $1;

'$%%/eras/alias' > '|eras|alias';
'$%%/eras/eraNames/alias' > '|eraNames|alias';
'$%%/months/alias' > '|months|alias';
'$%%/alias' > '|all|alias';

'$%%/week/' ($element) > '|week|' $1;

'$%%/days/dayContext[@type="' ($avalue) '"]/dayWidth[@type="' ($avalue) '"]/day[@type="' ('sun') '"]' > '|day|1-sunday:' $1 '-' $2;
'$%%/days/dayContext[@type="' ($avalue) '"]/dayWidth[@type="' ($avalue) '"]/day[@type="' ('mon') '"]' > '|day|2-monday:' $1 '-' $2;
'$%%/days/dayContext[@type="' ($avalue) '"]/dayWidth[@type="' ($avalue) '"]/day[@type="' ('tue') '"]' > '|day|3-tuesday:' $1 '-' $2;
'$%%/days/dayContext[@type="' ($avalue) '"]/dayWidth[@type="' ($avalue) '"]/day[@type="' ('wed') '"]' > '|day|4-wednesday:' $1 '-' $2;
'$%%/days/dayContext[@type="' ($avalue) '"]/dayWidth[@type="' ($avalue) '"]/day[@type="' ('thu') '"]' > '|day|5-thursday:' $1 '-' $2;
'$%%/days/dayContext[@type="' ($avalue) '"]/dayWidth[@type="' ($avalue) '"]/day[@type="' ('fri') '"]' > '|day|6-friday:' $1 '-' $2;
'$%%/days/dayContext[@type="' ($avalue) '"]/dayWidth[@type="' ($avalue) '"]/day[@type="' ('sat') '"]' > '|day|7-saturday:' $1 '-' $2;

'$%%/quarters/quarterContext[@type="' ($avalue) '"]/quarterWidth[@type="' ($avalue) '"]/quarter[@type="' ($avalue) '"]' > '|quarter|[' $3 ']-' $1 '-' $2;

'$%%/' ([ap]) 'm' > '|day-period|' $1 'm';

# //ldml/dates/calendars/calendar[@type="gregorian"]/dayPeriods/dayPeriodContext[@type="format"]/dayPeriodWidth[@type="wide"]/dayPeriod[@type="am"]

'$%%/dayPeriods/dayPeriodContext[@type="' ($avalue) '"]/dayPeriodWidth[@type="' ($avalue) '"]/dayPeriod[@type="' ($avalue) '"]' > '|dayPeriod|[' $3 ']-' $1 '-' $2;
'$%%/dayPeriods/dayPeriodContext[@type="' ($avalue) '"]/dayPeriodWidth[@type="' ($avalue) '"]/alias' > '|dayPeriod|' $1 '-' $2 '-alias';
'$%%/dayPeriods/dayPeriodContext[@type="' ($avalue) '"]/alias' > '|dayPeriod|' $1 '-alias';
'$%%/dayPeriods/alias' > '|dayPeriod|-alias';

'$%%/cyclicNameSets/cyclicNameSet[@type="' ($avalue) '"]/cyclicNameContext[@type="' ($avalue) '"]/cyclicNameWidth[@type="' ($avalue) '"]/cyclicName[@type="' ([0-9]) '"]' > '|cyclicName|[0' $4 ']-' $1 '-' $2 '-' $3;
'$%%/cyclicNameSets/cyclicNameSet[@type="' ($avalue) '"]/cyclicNameContext[@type="' ($avalue) '"]/cyclicNameWidth[@type="' ($avalue) '"]/cyclicName[@type="' ($avalue) '"]' > '|cyclicName|[' $4 ']-' $1 '-' $2 '-' $3;
'$%%/cyclicNameSets/cyclicNameSet[@type="' ($avalue) '"]/cyclicNameContext[@type="' ($avalue) '"]/cyclicNameWidth[@type="' ($avalue) '"]/alias' > '|cyclicName|' $1 '-' $2 '-' $3 '-alias';

'$%%/fields/field[@type="' ($avalue) '"]/displayName' > '|field-label|' $1;

'$%%/dateTimeFormats/availableFormats/dateFormatItem[@id="' ($avalue) '"]' > '|pattern|' $1;
'$%%/dateTimeFormats/appendItems/appendItem[@request="' ($avalue) '"]' > '|pattern|append-' $1;

'$%%/dateTimeFormats/intervalFormats/intervalFormatItem[@id="' ($avalue) '"]/greatestDifference[@id="' ($avalue) '"]'     > '|pattern|interval-' $1 '-' $2;
'$%%/dateTimeFormats/intervalFormats/intervalFormatFallback'     > '|pattern|interval-fallback';

'$%%/dateFormats/default' > '|default|dateFormat';
'$%%/timeFormats/default' > '|default|timeFormat';
'$%%/months/default' > '|default|monthFormat';
'$%%/days/default' > '|default|dayFormat';
'$%%/dateTimeFormats/dateTimeFormatLength/dateTimeFormat[@type="standard"]/pattern[@type="standard"]' > '|pattern|date+time';
'$%%/dateTimeFormats/alias' > '|date+time|alias';
'$%%/dateFormats/alias' > '|date|alias';
'$%%/timeFormats/alias' > '|time|alias';

'$%%/fields/field[@type="' ($avalue) '"]/relative[@type="' ($avalue) '"]' > '|fields|' $1 ':' $2 ;

'/dates/fields/field[@type="' ($avalue) '"]/displayName' > '|field-label|' $1;
'/dates/fields/field[@type="' ($avalue) '"]/relative[@type="' ($avalue) '"]' > '|fields|' $1 ':' $2 ;

'/dates/timeZoneNames/zone[@type="' ($avalue) '"]/exemplarCity' > '0-names|time-zone-cities|' &prettyPathZone($1);
'/dates/timeZoneNames/zone[@type="' ($avalue) '"]/usesMetazone' (.*) > '3-time-zone|uses-metazone|' &prettyPathZone($1) '-uses-' $2;
'/dates/timeZoneNames/zone[@type="' ($avalue) '"]/' ($element) '/' ($element) > '0-names|time-zone-old|' &prettyPathZone($1) ':' $3 '-' $2;
'/dates/timeZoneNames/zone[@type="' ($avalue) '"]/' ($element) > '0-names|time-zone-old|' &prettyPathZone($1) ':' $2;
'/dates/timeZoneNames/metazone[@type="' ($avalue) '"]/' ($element) '/' ($element) > '0-names|metazone|' $1 ':' $3 '-' $2;
'/dates/timeZoneNames/metazone[@type="' ($avalue) '"]/' ($element) > '0-names|metazone|' $1 ':' $2;
'/dates/timeZoneNames/abbreviationFallback' (.*) > '3-deprecated|time-zones|abbreviationFallback' $1;
'/dates/timeZoneNames/hoursFormat' (.*) > '3-deprecated|time-zones|hoursFormat' $1;
'/dates/timeZoneNames/preferenceOrdering' (.*) > '3-deprecated|time-zones|preferenceOrdering' $1;

'/dates/timeZoneNames/' (.*) > '3-time-zone|pattern|' $1;

'/dates/dateRangePattern' > '3-time-zone|pattern|date-range';

'/numbers/currencies/currency[@type="' ($avalue) '"]/displayName[@type="' ($avalue) '"]' > '0-names|currency|' $1 ':name-' $2;
'/numbers/currencies/currency[@type="' ($avalue) '"]/displayName' > '0-names|currency|' $1 ':name';
'/numbers/currencies/currency[@type="' ($avalue) '"]/' ($element) '[@type="' ($avalue) '"]' > '0-names|currency|' $1 ':' $2 '-' $3;
'/numbers/currencies/currency[@type="' ($avalue) '"]/' ($element) > '0-names|currency|' $1 ':' $2;

'/numbers/symbols/' (.*) > '2-number|symbol|' $1;
'/numbers/symbols[@numberSystem="latn"]/' (.*) > '2-number|symbol|' $1;
'/numbers/symbols[@numberSystem="' ($avalue) '"]/' (.*) > '2-number|symbol|' $2 '-' $1;

'/numbers/' ([a-z]+) 'Formats/' ($element) '/' ($element) '[@type="' ($avalue) '"]/pattern[@type="standard"]' > '2-number|pattern|' $1;
'/numbers/' ([a-z]+) 'Formats[@numberSystem="latn"]/' ($element) '/' ($element) '[@type="' ($avalue) '"]/pattern[@type="standard"]' > '2-number|pattern|' $1;
'/numbers/' ([a-z]+) 'Formats[@numberSystem="' ($avalue) '"]/' ($element) '/' ($element) '[@type="' ($avalue) '"]/pattern[@type="standard"]' > '2-number|pattern|' $1 '-' $2;
'/numbers/decimalFormats/decimalFormatLength[@type="' ($avalue) '"]/decimalFormat[@type="standard"]/pattern[@type="' ($avalue) '"]' > '2-number|pattern|decimal-' $1 '-' $2;

'/numbers/' ([a-z]+) 'Formats[@numberSystem="latn"]/' ($element) '[@type="' ($avalue) '"]/' ($element) '[@type="standard"]/pattern[@type="' ($avalue) '"]' > '2-number|pattern|' $1 '-' $5;
'/numbers/' ([a-z]+) 'Formats[@numberSystem="' ($avalue) '"]/' ($element) '[@type="' ($avalue) '"]/' ($element) '[@type="standard"]/pattern[@type="' ($avalue) '"]' > '2-number|pattern|' $1 '-' $6 '-' $2;

# //ldml/numbers/decimalFormats/decimalFormatLength[@type="short"]/decimalFormat[@type="standard"]/pattern[@type="1000"]

'/numbers/currencyFormats[@numberSystem="latn"]/currencySpacing/beforeCurrency/' (.*) > '2-number|currency|match-before-' $1;
'/numbers/currencyFormats[@numberSystem="latn"]/currencySpacing/afterCurrency/' (.*) > '2-number|currency|match-after-' $1;
'/numbers/currencyFormats[@numberSystem="latn"]/unitPattern' > '2-number|currency|name-pattern';
'/numbers/currencyFormats[@numberSystem="' ($avalue) '"]/unitPattern' > '2-number|currency|name-pattern-' $1;
'/numbers/defaultNumberingSystem' > '2-number|numberingSystems|default';
'/numbers/otherNumberingSystems/native' > '2-number|numberingSystems|native';
'/numbers/otherNumberingSystems/finance' > '2-number|numberingSystems|financial';
'/numbers/otherNumberingSystems/traditional' > '2-number|numberingSystems|traditional';
'/posix/messages/' (.*) > '1-misc|posix|' $1;

'/units/unitLength[@type="' ($avalue) '"]/unit[@type="' ($avalue) '"]/unitPattern' > '0-units' $1 '|pattern|' $2 ;

#'[@alt="proposed' ($avalue) '"]' > '/' \u200B 'alt'; # remove!
'[@alt="' ($avalue) '"]' > '/' \u200B 'alt-' $1;

'[@count="' ($avalue) '"]' > '/' \u200B $1;

'/alias' > 'whole|file|alias';
'/characters/mapping[@registry="' ($element) '"]' > '3-deprecated|charset-registry|' $1;
'/layout/inList' > '1-misc|casing|in_lists';
'/layout/inText[@type="' ($avalue) '"]' > '1-misc|casing|' $1;

'/numbers/scientificFormats/default' > '3-deprecated|default|scientificFormats';

# This is used to mark any transformation that fails at some point
(.*) > '?%%' $1;


