Working to converge 'example5' stylesheets.
authorTony Graham
Sun, 09 Feb 2014 22:00:24 +0000
changeset 30 8a3f9f860c2e
parent 29 22ac957faf1a
child 31 2cc547dd6415
Working to converge 'example5' stylesheets.
FOPRunXSLTExt/examples/example5_saxon9_ahf61.xsl
FOPRunXSLTExt/examples/example5_saxon9_fop10.xsl
FOPRunXSLTExt/examples/ppl-extensions.xsl
FOPRunXSLTExt/examples/runsaxon9he_ahf61.sh.in
--- a/FOPRunXSLTExt/examples/example5_saxon9_ahf61.xsl	Sun Feb 09 21:29:06 2014 +0000
+++ b/FOPRunXSLTExt/examples/example5_saxon9_ahf61.xsl	Sun Feb 09 22:00:24 2014 +0000
@@ -11,35 +11,48 @@
 <xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="2.0"
+    xmlns:ppl="http://www.w3.org/community/ppl/ns/"
     xmlns:fo="http://www.w3.org/1999/XSL/Format"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
-    xmlns:runahf="http://org.w3c.ppl.xslt/saxon-extension"
     xmlns:ahf="http://www.antennahouse.com/names/XSL/AreaTree"
-    exclude-result-prefixes="xs ahf runahf">
+    exclude-result-prefixes="ppl xs ahf">
+
+<!-- Print and Page Layout Community Group extensions. -->
+<xsl:import href="ppl-extensions.xsl" />
 
 <!-- Common templates for formatting FOPRunXSLTExt examples -->
 <xsl:import href="formatting.xsl" />
 
+
+<!-- ============================================================= -->
+<!-- KEYS                                                          -->
+<!-- ============================================================= -->
+
+<!-- All 'box' elements in source. -->
 <xsl:key name="boxes" match="box" use="true()" />
 
-<!-- FOP -->
-<xsl:key name="blocks" match="block[exists(@prod-id)]" use="@prod-id" />
-<!-- Antenna House -->
-<xsl:key name="blocks" match="ahf:BlockViewportArea[exists(@id)]" use="@id" />
 
+<!-- ============================================================= -->
+<!-- STYLESHEET PARAMETERS                                         -->
+<!-- ============================================================= -->
+
+<!-- Initial font size. -->
 <xsl:param name="font-size" select="12" as="xs:double" />
 
-<!-- Where to write the output files. -->
-<xsl:param name="dest_dir" select="out" as="xs:string"/>
 <!-- Allowed difference in height between outer box and formatted
      paragraph text to be able to say paragraph fits within box and
      stop further iterations. -->
 <xsl:param name="tolerance" select="1" as="xs:double" />
+
 <!-- Difference between font-size.minimum and font-size.maximum below
      which it's not worth continuing. -->
 <xsl:param name="font-size-tolerance" select="0.01" as="xs:double" />
 
-<!-- Initial template -->
+
+<!-- ============================================================= -->
+<!-- INITIAL TEMPLATE                                              -->
+<!-- ============================================================= -->
+
 <xsl:template name="main">
   <xsl:message select="concat('tolerance: ', $tolerance)" />
   <xsl:message select="concat('font-size-tolerance: ', $font-size-tolerance)" />
@@ -90,12 +103,12 @@
 
   <xsl:variable
       name="area-tree"
-      select="runahf:area-tree($fo_tree)"
+      select="ppl:area-tree($fo_tree)"
       as="document-node()?" />
 
   <xsl:variable
       name="block"
-      select="key('blocks', key('boxes', true())[1]/@id, $area-tree)[1]"
+      select="ppl:block($area-tree, key('boxes', true())[1]/@id)"
       as="element()" />
 
   <xsl:variable
--- a/FOPRunXSLTExt/examples/example5_saxon9_fop10.xsl	Sun Feb 09 21:29:06 2014 +0000
+++ b/FOPRunXSLTExt/examples/example5_saxon9_fop10.xsl	Sun Feb 09 22:00:24 2014 +0000
@@ -11,35 +11,48 @@
 <xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="2.0"
+    xmlns:ppl="http://www.w3.org/community/ppl/ns/"
     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"
     xmlns:ahf="http://www.antennahouse.com/names/XSL/AreaTree"
-    exclude-result-prefixes="xs ahf runfop">
+    exclude-result-prefixes="ppl xs ahf">
+
+<!-- Print and Page Layout Community Group extensions. -->
+<xsl:import href="ppl-extensions.xsl" />
 
 <!-- Common templates for formatting FOPRunXSLTExt examples -->
 <xsl:import href="formatting.xsl" />
 
+
+<!-- ============================================================= -->
+<!-- KEYS                                                          -->
+<!-- ============================================================= -->
+
+<!-- All 'box' elements in source. -->
 <xsl:key name="boxes" match="box" use="true()" />
 
-<!-- FOP -->
-<xsl:key name="blocks" match="block[exists(@prod-id)]" use="@prod-id" />
-<!-- Antenna House -->
-<xsl:key name="blocks" match="ahf:BlockViewportArea[exists(@id)]" use="@id" />
 
+<!-- ============================================================= -->
+<!-- STYLESHEET PARAMETERS                                         -->
+<!-- ============================================================= -->
+
+<!-- Initial font size. -->
 <xsl:param name="font-size" select="12" as="xs:double" />
 
-<!-- Where to write the output files. -->
-<xsl:param name="dest_dir" select="out" as="xs:string"/>
 <!-- Allowed difference in height between outer box and formatted
      paragraph text to be able to say paragraph fits within box and
      stop further iterations. -->
 <xsl:param name="tolerance" select="1" as="xs:double" />
+
 <!-- Difference between font-size.minimum and font-size.maximum below
      which it's not worth continuing. -->
 <xsl:param name="font-size-tolerance" select="0.01" as="xs:double" />
 
-<!-- Initial template -->
+
+<!-- ============================================================= -->
+<!-- INITIAL TEMPLATE                                              -->
+<!-- ============================================================= -->
+
 <xsl:template name="main">
   <xsl:message select="concat('tolerance: ', $tolerance)" />
   <xsl:message select="concat('font-size-tolerance: ', $font-size-tolerance)" />
@@ -90,12 +103,12 @@
 
   <xsl:variable
       name="area-tree"
-      select="runfop:area-tree($fo_tree)"
+      select="ppl:area-tree($fo_tree)"
       as="document-node()?" />
 
   <xsl:variable
       name="bpd"
-      select="key('blocks', key('boxes', true())[1]/@id, $area-tree)[1]/block/@bpd"
+      select="ppl:block($area-tree, key('boxes', true())[1]/@id)/block/@bpd"
       as="xs:integer" />
 
   <xsl:variable
@@ -106,8 +119,29 @@
   <xsl:message select="concat('bpd: ', $bpd)" />
   <xsl:message select="concat('target-height: ', $target-height)" />
   <xsl:choose>
+    <xsl:when test="$target-height - $bpd > 0 and
+                    $target-height - $bpd &lt; $tolerance">
+      <xsl:message>It fits.  Using <xsl:value-of select="$font-size" />.</xsl:message>
+      <xsl:apply-templates select="/">
+        <xsl:with-param
+            name="overrides"
+            select="$overrides"
+            as="document-node()"
+            tunnel="yes" />
+      </xsl:apply-templates>
+    </xsl:when>
+    <xsl:when test="$font-size.maximum - $font-size.minimum &lt; $font-size-tolerance">
+      <xsl:message>Font size difference less than $font-size-tolerance.  Using <xsl:value-of select="$font-size" />.</xsl:message>
+      <xsl:apply-templates select="/">
+        <xsl:with-param
+            name="overrides"
+            select="$overrides"
+            as="document-node()"
+            tunnel="yes" />
+      </xsl:apply-templates>
+    </xsl:when>
     <xsl:when test="$iteration eq $iteration-max">
-      <xsl:message>Maximum iterations.</xsl:message>
+      <xsl:message>Maximum iterations.  Using <xsl:value-of select="$font-size" />.</xsl:message>
       <xsl:apply-templates select="/">
         <xsl:with-param
             name="overrides"
--- a/FOPRunXSLTExt/examples/ppl-extensions.xsl	Sun Feb 09 21:29:06 2014 +0000
+++ b/FOPRunXSLTExt/examples/ppl-extensions.xsl	Sun Feb 09 22:00:24 2014 +0000
@@ -17,16 +17,44 @@
     xmlns:ppl="http://www.w3.org/community/ppl/ns/"
     xmlns:fo="http://www.w3.org/1999/XSL/Format"
     xmlns:xalan="http://xml.apache.org/xalan"
+    xmlns:se="http://org.w3c.ppl.xslt/saxon-extension"
     xmlns:runfop="runfop"
     xmlns:runahf="runahf"
-    exclude-result-prefixes="ppl xalan runahf runfop">
+    xmlns:ahf="http://www.antennahouse.com/names/XSL/AreaTree"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="ppl se ahf xalan runahf runfop xs">
+
+<!-- ============================================================= -->
+<!-- KEYS                                                          -->
+<!-- ============================================================= -->
+
+<!-- Blocks in area tree.  Different formatters have different
+     representatioons in area tree. -->
+<!-- FOP -->
+<xsl:key name="blocks"
+	 match="block[@prod-id]"
+	 use="@prod-id" />
+<!-- Antenna House -->
+<xsl:key name="blocks"
+	 match="ahf:BlockViewportArea[@id]"
+	 use="@id" />
+
+
+<!-- ============================================================= -->
+<!-- STYLESHEET PARAMETERS                                         -->
+<!-- ============================================================= -->
 
 <!-- Formatter to run.  Used when selecting which extension function
      to run. -->
 <!-- Seems that you can't use namespaced parameters on the Xalan
-     command line, otherwise would have been ppl:formatter. -->
+     command line, otherwise could have been ppl:formatter. -->
 <xsl:param name="ppl-formatter" select="'fop'" />
 
+
+<!-- ============================================================= -->
+<!-- XALAN EXTENSION FUNCTION DEFINITIONS                          -->
+<!-- ============================================================= -->
+
 <xalan:component prefix="runfop" functions="areaTree" elements="">
   <xalan:script lang="javaclass"
 		src="xalan://org.w3c.ppl.xslt.ext.fop.xalan" />
@@ -37,17 +65,56 @@
 		src="xalan://org.w3c.ppl.xslt.ext.ahf.xalan" />
 </xalan:component>
 
+
+<!-- ============================================================= -->
+<!-- XSLT 1.0-COMPATIBLE NAMED TEMPLATE                            -->
+<!-- ============================================================= -->
+
+<!-- Named template for use with XSLT 1.0 processors such as
+     Xalan. -->
 <xsl:template name="ppl:area-tree">
   <xsl:param name="fo-tree"/>
 
   <xsl:choose>
-    <xsl:when test="$ppl-formatter = 'ahf'">
-      <xsl:copy-of select="runahf:RunAHFXalan.areaTree($fo-tree)"/>
+    <xsl:when test="contains(system-property('xsl:vendor-url'),
+		             'xalan-j')">
+      <xsl:choose>
+	<xsl:when test="$ppl-formatter = 'ahf'">
+	  <xsl:copy-of
+	      select="runahf:RunAHFXalan.areaTree($fo-tree)"
+	      use-when="function-available('runahf:RunAHFXalan.areaTree')" />
+	</xsl:when>
+	<xsl:otherwise>
+	  <xsl:copy-of
+	      select="runfop:RunFOPXalan.areaTree($fo-tree)"
+	      use-when="function-available('runahf:RunFOPXalan.areaTree')" />
+	</xsl:otherwise>
+      </xsl:choose>
     </xsl:when>
-    <xsl:otherwise>
-      <xsl:copy-of select="runfop:RunFOPXalan.areaTree($fo-tree)"/>
-    </xsl:otherwise>
+    <xsl:when test="system-property('xsl:product-name') = 'SAXON'">
+      <xsl:sequence select="se:area-tree($fo-tree)"/>
+    </xsl:when>
   </xsl:choose>
 </xsl:template>
 
+
+<!-- ============================================================= -->
+<!-- XSLT 2.0-COMPATIBLE FUNCTIONS                                 -->
+<!-- ============================================================= -->
+
+<!-- Function for use with XSLT 2.0 processors such as
+     Saxon. -->
+<xsl:function name="ppl:area-tree" as="document-node()">
+  <xsl:param name="fo-tree" as="node()" />
+
+  <xsl:sequence select="se:area-tree($fo-tree)"/>
+</xsl:function>
+
+<xsl:function name="ppl:block" as="node()?">
+  <xsl:param name="area-tree" as="document-node()" />
+  <xsl:param name="id" as="xs:string" />
+
+  <xsl:sequence select="key('blocks', $id, $area-tree)[1]" />
+</xsl:function>
+
 </xsl:stylesheet>
\ No newline at end of file
--- a/FOPRunXSLTExt/examples/runsaxon9he_ahf61.sh.in	Sun Feb 09 21:29:06 2014 +0000
+++ b/FOPRunXSLTExt/examples/runsaxon9he_ahf61.sh.in	Sun Feb 09 22:00:24 2014 +0000
@@ -31,4 +31,4 @@
 CP=$SAXON:@[email protected]
 CP=$CP:@[email protected]
 
-java -cp $CP net.sf.saxon.Transform -init:org.w3c.ppl.xslt.ext.ahf.saxon.RunAHFExtInitializer -s:$1 -xsl:$2 -o:$3 -it:main
\ No newline at end of file
+java -cp $CP net.sf.saxon.Transform -init:org.w3c.ppl.xslt.ext.ahf.saxon.RunAHFExtInitializer -s:$1 -xsl:$2 -o:$3 -it:main ppl-formatter=ahf