find_content.xsl 3.34 KB
Newer Older
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--find_content.xsl creates a ANT file prepare_hdoc.ant-->
3
<xsl:stylesheet
4
5
6
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:h="urn:utc.fr:ics:hdoc:container"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
7
8
9
10

	<xsl:param name="BaseDirectory" required="yes" as="xs:string"/>
  <xsl:param name="TempDirectory" required="yes" as="xs:string"/>

11
    <xsl:output method="xml" indent="yes"/>
12

13
    <xsl:template match="h:container">
14
        <project name="hdoc_to_pdf" basedir=".." default="main">
15
16
17
18
19
20
21
            <property name="lib" location="lib"/>
            <property name="Schema" location="schemas"/>
            <taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask">
                <classpath>
                    <pathelement location="${lib}/jing.jar"/>
                </classpath>
            </taskdef>
22
23
24
25
26
            <target name="main">
                <xsl:apply-templates/>
            </target>
        </project>
    </xsl:template>
27

28
29
30
    <xsl:template match="h:rootfiles">
        <xsl:apply-templates/>
    </xsl:template>
31

32
33
34
    <xsl:template match="h:rootfile">
        <xsl:variable name="path" select="@full-path"/>

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        <xsl:analyze-string select="$path" regex="\.?[-_0-9a-zA-Z]+(\.[-_0-9a-zA-Z]+)?$">
            <xsl:matching-substring>
            <echo message="MATCHING TEST  :"/>
            <echo>
                <xsl:attribute name="message"><xsl:value-of select="."/></xsl:attribute>
            </echo>
            <xsl:variable name="filename">
                <xsl:value-of select="."/>
            </xsl:variable>

            <xsl:variable name="dirpath" select="concat($TempDirectory, '/', substring($path, 1, string-length($path) - string-length($filename) - 1))"/>

            <echo message="Path : {$path}"/>
            <echo message="Filename : {$filename}"/>
            <echo message="Dirpath : {$dirpath}"/>

51
52
53
54
55
56
57
58
59
            <trycatch property="foo" reference="bar">
                <try>
                    <jing file="{$TempDirectory}/{$path}" rngfile="${{Schema}}/xhtml/hdoc1-xhtml.rng"></jing>
                </try>
                <catch>
                    <echo>Validation failed</echo>
                </catch>
            </trycatch>

60
            <copy file="{$BaseDirectory}/css/main.css" tofile="{$dirpath}/main.css"/>
61
62
63
64
            <copy file="{$BaseDirectory}/font/cmunrm.ttf" tofile="{$dirpath}/cmunrm.ttf"/>
            <copy file="{$BaseDirectory}/font/cmunrb.ttf" tofile="{$dirpath}/cmunrb.ttf"/>
            <copy file="{$BaseDirectory}/font/cmunti.ttf" tofile="{$dirpath}/cmunti.ttf"/>
            <copy file="{$BaseDirectory}/font/cmuntt.ttf" tofile="{$dirpath}/cmuntt.ttf"/>
65

66
67
68
69
            <xslt in="{$TempDirectory}/{$path}" out="{$dirpath}/hdoc_nsless.xhtml" style="xsl/ns_remover.xsl" classpath="./lib/saxon9he.jar"/>
            <xslt in="{$dirpath}/hdoc_nsless.xhtml" out="{$dirpath}/flat_hdoc.xhtml" style="xsl/hdoc_flattenizer.xsl" classpath="./lib/saxon9he.jar"/>
            <xslt in="{$dirpath}/flat_hdoc.xhtml" out="{$dirpath}/final.xhtml" style="xsl/last_transformer.xsl" classpath="./lib/saxon9he.jar"/>

70
            <propertyfile file="{$TempDirectory}/my.properties">
71
72
                <entry key="dirpath" value="{$dirpath}"/>
            </propertyfile>
73
74
75
76

            </xsl:matching-substring>
        </xsl:analyze-string>

77
78
    </xsl:template>
</xsl:stylesheet>