blob: 22c172329f618d2b0339e2f9d5a70c41513e41d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
$ARGV0 = shift @ARGV;
print <<EOF;
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:include href="./modelpreprocess.xsl"/>
<xsl:template match="namespace-alias[\@id]">
<xsl:variable name="value">
<xsl:call-template name="getnamespaceid">
<xsl:with-param name="id" select="\@id" />
</xsl:call-template>
</xsl:variable>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="id">
<xsl:value-of select="\$value"/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template name="getnamespaceid">
<xsl:param name='id'/>
<xsl:choose>
EOF
# print the mapping
open ( NAMESPACES, $ARGV0 ) || die "can't open namespace file: $!";
$group = 0;
$i = 1;
while ( <NAMESPACES> )
{
chomp( $_ );
$_ =~ s/\s*//g;
if ( $_ =~ m/^$/ )
{
# Start a new group
$i = 0;
$group++;
}
elsif ( $_ =~ m/^[^#]/ )
{
# Neither an empty line nor a comment
$_ =~ /^[a-zA-Z0-9-_]+$/ or die "Invalid namespace token $_";
$_ =~ s/-/_/g;
$no = $group*10 + $i;
print <<EOF;
<xsl:when test="\$id = '$_'">
<xsl:text>$no</xsl:text>
</xsl:when>
EOF
++$i;
}
}
print <<EOF;
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
EOF
|