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