Split formatting templates out into 'formatting.xsl' and using 'main' initial named template when using Saxon.
authorTony Graham
Sat, 27 Apr 2013 17:28:05 +0100
changeset 7 d55561ef829d
parent 6 00792729e157
child 8 f847271f8f76
Split formatting templates out into 'formatting.xsl' and using 'main' initial named template when using Saxon.
FOPRunXSLTExt/examples/example1_saxon9_fop10.xsl
FOPRunXSLTExt/examples/formatting.xsl
FOPRunXSLTExt/examples/runsaxon9he_fop10.sh.in
--- a/FOPRunXSLTExt/examples/example1_saxon9_fop10.xsl	Sat Apr 27 17:25:55 2013 +0100
+++ b/FOPRunXSLTExt/examples/example1_saxon9_fop10.xsl	Sat Apr 27 17:28:05 2013 +0100
@@ -1,56 +1,44 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="2.0"
-xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-xmlns:fo="http://www.w3.org/1999/XSL/Format"
-xmlns:xs="http://www.w3.org/2001/XMLSchema"
-xmlns:runfop="http://org.w3c.ppl.xslt/saxon-extension">
+<!-- ============================================================= -->
+<!-- FOPRunXSLTExt Saxon example 1                                 -->
+<!--                                                               -->
+<!-- See http://www.w3.org/community/ppl/wiki/FOPRunXSLTExt        -->
+<!--                                                               -->
+<!-- Requires Saxon 9.4 or later and FOP 1.0                       -->
+<!--                                                               -->
+<!-- Produced by the Print and Page Layout Community Group @ W3C   -->
+<!-- ============================================================= -->
+<xsl:stylesheet
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    version="2.0"
+    xmlns:fo="http://www.w3.org/1999/XSL/Format"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:runfop="http://org.w3c.ppl.xslt/saxon-extension"
+    exclude-result-prefixes="xs runfop">
 
-<xsl:param name="dest_dir" />
+<!-- Common templates for formatting FOPRunXSLTExt examples -->
+<xsl:import href="formatting.xsl" />
+
+<!-- Where to write the output files. -->
+<xsl:param name="dest_dir" select="out" as="xs:string"/>
 <xsl:param name="area_tree_filename" />
 
-<xsl:template match="/">
-<xsl:variable name="fo_tree">
-<fo:root>
-      <fo:layout-master-set>
-        <fo:simple-page-master master-name="test-page">
-          <fo:region-body margin="1in"/>
-        </fo:simple-page-master>
-      </fo:layout-master-set>
+<!-- Initial template -->
+<xsl:template name="main">
+  <!-- Save the FO tree in a variable. -->
+  <xsl:variable name="fo_tree">
+    <xsl:apply-templates select="/" />
+  </xsl:variable>
 
-      <fo:page-sequence master-reference="test-page">
-        <fo:flow flow-name="xsl-region-body">
-          <xsl:apply-templates select="example" />
-       </fo:flow>
-      </fo:page-sequence>
-    </fo:root>
-</xsl:variable>
+  <xsl:variable name="area_tree_file"
+		select="concat($dest_dir, '/', $area_tree_filename)" />
 
-<xsl:variable name="area_tree_file" select="concat($dest_dir, '/', $area_tree_filename)" />
+  <xsl:message>Area tree filename = <xsl:value-of select="$area_tree_file" /></xsl:message>
 
-<xsl:message>Area tree filename = <xsl:value-of select="$area_tree_file" /></xsl:message>
-
-<url>
-  <xsl:value-of select="runfop:area-tree-url($fo_tree, $area_tree_file)"/>
+  <url>
+    <xsl:value-of select="runfop:area-tree-url($fo_tree, $area_tree_file)"/>
   </url>
 
 </xsl:template>
 
-
-<xsl:template match="header">
-  <fo:block font-size="14pt" font-family="verdana" color="red"
-  space-before="5mm" space-after="5mm">
-    <xsl:apply-templates/>
-  </fo:block>
-</xsl:template>
-
-
-<xsl:template match="paragraph">
-  <fo:block text-indent="5mm" font-family="verdana" font-size="12pt">
-    <xsl:attribute name="id">
-      <xsl:value-of select="@id" />
-    </xsl:attribute>
-    <xsl:apply-templates/>
-  </fo:block>
-</xsl:template>
-
 </xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FOPRunXSLTExt/examples/formatting.xsl	Sat Apr 27 17:28:05 2013 +0100
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ============================================================= -->
+<!-- Common templates for formatting FOPRunXSLTExt examples        -->
+<!--                                                               -->
+<!-- See http://www.w3.org/community/ppl/wiki/FOPRunXSLTExt        -->
+<!--                                                               -->
+<!-- Requires Saxon 9.4 or later and FOP 1.0                       -->
+<!--                                                               -->
+<!-- Produced by the Print and Page Layout Community Group @ W3C   -->
+<!-- ============================================================= -->
+<xsl:stylesheet
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    version="2.0"
+    xmlns:fo="http://www.w3.org/1999/XSL/Format"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs">
+
+<xsl:template match="/">
+  <fo:root>
+    <fo:layout-master-set>
+      <fo:simple-page-master master-name="test-page">
+	<fo:region-body margin="1in"/>
+      </fo:simple-page-master>
+    </fo:layout-master-set>
+
+    <fo:page-sequence master-reference="test-page">
+      <fo:flow flow-name="xsl-region-body">
+	<xsl:apply-templates select="example" />
+      </fo:flow>
+    </fo:page-sequence>
+  </fo:root>
+</xsl:template>
+
+<xsl:template match="header">
+  <fo:block font-size="14pt" font-family="verdana, sans-serif"
+	    color="red" space-before="5mm" space-after="5mm">
+    <xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+<xsl:template match="paragraph">
+  <fo:block id="{@id}" text-indent="5mm"
+	    font-family="verdana, sans-serif" font-size="12pt">
+    <xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+<xsl:template match="svg">
+  <fo:instream-foreign-object id="{@id}">
+    <xsl:copy-of select="document(@href)"/>
+  </fo:instream-foreign-object>
+</xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
--- a/FOPRunXSLTExt/examples/runsaxon9he_fop10.sh.in	Sat Apr 27 17:25:55 2013 +0100
+++ b/FOPRunXSLTExt/examples/runsaxon9he_fop10.sh.in	Sat Apr 27 17:28:05 2013 +0100
@@ -10,4 +10,4 @@
 CP=$CP:$FOP/lib/batik-all-1.7.jar
 CP=$CP:@FOPRunXSLTExt.jar@
 
-java -cp $CP net.sf.saxon.Transform -init:org.w3c.ppl.xslt.ext.fop.saxon.RunFOPExtInitializer -s:$1 -xsl:$2 -o:$3 dest_dir=$4 area_tree_filename=$5
\ No newline at end of file
+java -cp $CP net.sf.saxon.Transform -init:org.w3c.ppl.xslt.ext.fop.saxon.RunFOPExtInitializer -s:$1 -xsl:$2 -o:$3 -it:main dest_dir=$4 area_tree_filename=$5
\ No newline at end of file