Adjusting lists two different ways. Using five columns for source listings.
authorTony Graham
Tue, 29 Jul 2014 00:32:37 +0100
changeset 54 3fe35c97a8a8
parent 53 606c85f64e78
child 55 873cf39a5e9c
Adjusting lists two different ways. Using five columns for source listings.
FOPRunXSLTExt/examples/balisage2014.xsl
--- a/FOPRunXSLTExt/examples/balisage2014.xsl	Mon Jul 28 23:30:12 2014 +0100
+++ b/FOPRunXSLTExt/examples/balisage2014.xsl	Tue Jul 29 00:32:37 2014 +0100
@@ -118,8 +118,9 @@
 		    as="element()*">
       <fo:block-container
 	  font-size="9pt"
-	  axf:column-count="4"
-	  column-gap="48pt">
+	  axf:column-count="5"
+	  column-gap="48pt"
+	  space-before="30pt">
 	<fo:block xsl:use-attribute-sets="title">XML</fo:block>
 	<fo:block xsl:use-attribute-sets="code-block"
 		  background-color="#f0f3f3">
@@ -364,25 +365,21 @@
     </xsl:apply-templates>
   </xsl:variable>
 
-  <xsl:variable
-      name="area-tree"
-      select="ppl:area-tree($fo_tree)"
-      as="document-node()?" />
+  <xsl:variable name="area-tree"
+		select="ppl:area-tree($fo_tree)"
+		as="document-node()?" />
 
-  <xsl:variable
-      name="block"
-      select="ppl:block-by-id($area-tree, 'header')"
-      as="element()" />
+  <xsl:variable name="block"
+		select="ppl:block-by-id($area-tree, 'header')"
+		as="element()" />
 
-  <xsl:variable
-      name="ipd"
-      select="ppl:block-ipd($block)"
-      as="xs:double" />
+  <xsl:variable name="ipd"
+		select="ppl:block-ipd($block)"
+		as="xs:double" />
 
-  <xsl:variable
-      name="available-ipd"
-      select="ppl:block-available-ipd($block)"
-      as="xs:double" />
+  <xsl:variable name="available-ipd"
+		select="ppl:block-available-ipd($block)"
+		as="xs:double" />
 
   <xsl:apply-templates select="." mode="#default">
     <xsl:with-param name="overrides" tunnel="yes">
@@ -423,10 +420,7 @@
       role="{local-name()}" border="{(@border, 'medium solid black')[1]}"
       width="{@width}" height="{@height}" padding="12pt"
       id="{@id}" axf:column-count="{(@columns, 1)[1]}"
-      column-gap="48pt">
-    <xsl:if test="key('overrides', @id, $overrides)/@rotate = 'yes'">
-      <xsl:attribute name="reference-orientation" select="'270'" />
-    </xsl:if>
+      column-gap="48pt" space-before="12pt">
     <xsl:if test="key('overrides', @id, $overrides)/@font-size">
       <xsl:attribute name="font-size"
                      select="concat(key('overrides', @id, $overrides)/@font-size, 'pt')" />
@@ -448,28 +442,58 @@
 </xsl:template>
 
 <xsl:template match="list">
-  <xsl:param name="overrides" select="$overrides" as="document-node()" tunnel="yes"/>
+  <xsl:param name="font-size" as="xs:double" tunnel="yes" />
+
+  <!-- Get a document containing just this element. -->
+  <xsl:variable name="tmp-doc">
+    <box id="labels" font-size="{$font-size}">
+      <xsl:for-each select="item/@label">
+	<paragraph>
+	  <xsl:value-of select="." />
+	</paragraph>
+      </xsl:for-each>
+    </box>
+  </xsl:variable>
+
+  <!-- Save the FO tree for the labels in a variable. -->
+  <xsl:variable name="fo_tree">
+    <xsl:apply-templates select="$tmp-doc" mode="#default">
+      <xsl:with-param name="overrides" as="document-node()" tunnel="yes">
+	<xsl:document>
+	  <overrides>
+	    <override id="labels" font-size="{$font-size}" />
+	  </overrides>
+	</xsl:document>
+      </xsl:with-param>
+    </xsl:apply-templates>
+  </xsl:variable>
+
+  <xsl:variable name="area-tree"
+		select="ppl:area-tree($fo_tree)"
+		as="document-node()?" />
+
+  <xsl:variable name="block"
+		select="ppl:block-by-id($area-tree, 'labels')"
+		as="element()" />
+
+  <xsl:variable name="ipd"
+		select="ppl:block-ipd($block)"
+		as="xs:double" />
+
+  <xsl:message select="concat('list labels ipd: ', $ipd)"/>
+
   <fo:list-block
-      provisional-distance-between-starts="{if (@label-width = 'narrow')
-                                              then '10mm'
-                                            else '35mm'}"
-      provisional-label-separation="4pt"
-      space-after="3pt"
+      provisional-distance-between-starts="{$ipd}pt + 0.5em"
+      provisional-label-separation="1em"
+      space-before="0.25em"
+      space-after="0.25em"
       id="{@id}">
-    <!-- If we know the exact label width, set the provisional
-         distance between starts to the width plus the label
-         separation. -->
-    <xsl:if test="exists(key('overrides', @id, $overrides))">
-      <xsl:attribute
-          name="provisional-distance-between-starts"
-          select="concat(key('overrides', @id, $overrides)/@label-width, ' + 4pt')" />
-    </xsl:if>
     <xsl:apply-templates/>
   </fo:list-block>
 </xsl:template>
 
 <xsl:template match="item">
-  <fo:list-item space-before="3pt">
+  <fo:list-item space-before="3pt" relative-align="baseline">
     <fo:list-item-label end-indent="label-end()">
       <fo:block color="red">
         <xsl:apply-templates select="@label"/>
@@ -494,15 +518,54 @@
 </xsl:template>
 
 <xsl:template match="api-list/item">
+  <xsl:param name="font-size" as="xs:double" tunnel="yes" />
+
   <fo:list-item space-before="3pt" keep-together.within-column="always">
     <fo:list-item-label end-indent="0">
-      <fo:block xsl:use-attribute-sets="code"
-		background-color="transparent">
-        <xsl:apply-templates select="function"/>
-      </fo:block>
+      <xsl:apply-templates select="function"/>
     </fo:list-item-label>
     <fo:list-item-body start-indent="body-start()">
-      <fo:block />
+      <!-- Get a document containing just the label. -->
+      <xsl:variable name="tmp-doc">
+	<box id="function" font-size="{$font-size}">
+	  <paragraph>
+	    <code>
+	      <xsl:value-of select="function" />
+	    </code>
+	  </paragraph>
+	</box>
+      </xsl:variable>
+
+      <!-- Save the FO tree for the function in a variable. -->
+      <xsl:variable name="fo_tree">
+	<xsl:apply-templates select="$tmp-doc" mode="#default">
+	  <xsl:with-param name="overrides" as="document-node()" tunnel="yes">
+	    <xsl:document>
+	      <overrides>
+		<override id="function" font-size="{$font-size}" />
+	      </overrides>
+	    </xsl:document>
+	  </xsl:with-param>
+	</xsl:apply-templates>
+      </xsl:variable>
+
+      <xsl:variable name="area-tree"
+		    select="ppl:area-tree($fo_tree)"
+		    as="document-node()?" />
+
+      <xsl:variable name="block"
+		    select="ppl:block-by-id($area-tree, 'function')"
+		    as="element()" />
+
+      <xsl:variable name="ipd"
+		    select="ppl:block-ipd($block)"
+		    as="xs:double" />
+
+      <xsl:message select="concat('function: ', function, '; ipd: ', $ipd)"/>
+
+      <xsl:if test="$ipd > ppl:length-to-pt('35mm')">
+	<fo:block />
+      </xsl:if>
       <fo:block space-before="1.5em"
 		space-before.conditionality="retain">
         <xsl:apply-templates select="def" />
@@ -511,6 +574,12 @@
   </fo:list-item>
 </xsl:template>
 
+<xsl:template match="item/function">
+  <fo:block xsl:use-attribute-sets="code">
+    <xsl:apply-templates />
+  </fo:block>
+</xsl:template>
+
 <xsl:template match="svg">
   <fo:instream-foreign-object
       id="{@id}" content-height="1.8em"