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