poetry_print.xsl
author Fabien Ninoles <fabien@tzone.org>
Mon, 14 Sep 2015 11:24:14 -0400
branchstyles
changeset 15 27a2a404231e
parent 11 e2d28bf2a3bb
child 21 ce4faf661fca
permissions -rw-r--r--
More support for link.

<?xml version="1.0"?>
<xsl:stylesheet version="1.1"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xt="http://www.jclark.com/xt"
  extension-element-prefixes="xt" 
  xmlns="http://www.w3.org/1999/XSL/Format">

<xsl:import href="common.xsl"/>
<xsl:import href="print.xsl"/>
<xsl:import href="masters_print.xsl"/>

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

<xsl:attribute-set name="standard-block">
  <xsl:attribute name="text-indent">10mm</xsl:attribute>
  <xsl:attribute name="space-before">10pt</xsl:attribute>
  <xsl:attribute name="space-before.conditionality">discard</xsl:attribute>
  <xsl:attribute name="text-align">justify</xsl:attribute>
</xsl:attribute-set>

<xsl:template name="static-content">
  <xsl:param name="title"/>
  <static-content flow-name="xsl-region-before">
    <block border-after-style="solid">
      <table width="100%" table-layout="fixed">
            <table-column column-width="proportional-column-width(1)"
                  number-columns-repeated="2"/>
            <table-body>
              <table-row>
                <table-cell>
                  <block text-align="start"><xsl:value-of select="$title"/></block>
                </table-cell>
              </table-row>
            </table-body>
          </table>
        </block>
      </static-content>
      <static-content flow-name="xsl-region-after">
        <block space-before="10mm" border-before-style="solid">
          <table space-before="2mm" width="100%" table-layout="fixed">
            <table-column column-width="proportional-column-width(1)"
                  number-columns-repeated="2"/>
            <table-body>
              <table-row>
                <table-cell>
                  <block text-align="end">
		    <xsl:text>page </xsl:text>
                    <page-number/>
                  </block>
                </table-cell>
              </table-row>
            </table-body>
          </table>
        </block>
      </static-content>
</xsl:template>

<!-- book -->
<xsl:template match="book">
  <root>
    <xsl:call-template name="master-set"/>
    <page-sequence master-reference="book-sequence">
      <xsl:call-template name="static-content">
	<xsl:with-param name="title">
	  <xsl:apply-templates select="descendant::title[1]"/>
	</xsl:with-param>
      </xsl:call-template>
      <xsl:variable name="id">
	<xsl:call-template name="get-id"/>
      </xsl:variable>
      <flow flow-name="xsl-region-body">
	<block id="{$id}"/>
	<xsl:apply-templates select="*[name(.)!='section']"/>
      </flow>
    </page-sequence>
    <xsl:apply-templates select="section"/> 
  </root>
</xsl:template>

<xsl:template 
    match="/book/section|section[poetry]|poetry|/book/addendum">
  <page-sequence master-reference="book-sequence">
    <xsl:call-template name="static-content">
      <xsl:with-param name="title">
	<xsl:choose>
	  <xsl:when test="name(.)='preambule'">
	    <xsl:text>Préambule</xsl:text>
	  </xsl:when>
	  <xsl:when test="name(.)='addendum'">
	    <xsl:text>Addendum</xsl:text>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:apply-templates select="descendant::title[1]"/>
	  </xsl:otherwise>
	</xsl:choose>
      </xsl:with-param>
    </xsl:call-template>
    <xsl:variable name="id">
      <xsl:call-template name="get-id"/>
    </xsl:variable>
    <flow flow-name="xsl-region-body">
      <block>
	    <xsl:if test="name(.) != 'poetry'">
	      <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
	    </xsl:if>
	    <xsl:apply-templates select="*[not(poetry)][name(.)!='poetry']"/>
	    <xsl:if test="section[poetry]">
	      <list-block text-indent="15mm" space-before="15pt">
	        <xsl:apply-templates select="section[poetry]" mode="toc"/>
	      </list-block>
        </xsl:if>
      </block>
    </flow>    
  </page-sequence>
  <xsl:apply-templates select="poetry|section[poetry]"/> 
</xsl:template>

<xsl:template match="section|poetry" mode="toc">
  <list-item>
    <xsl:call-template name="list-label"/>
    <list-item-body start-indent="body-start()">
      <block>
	    <xsl:apply-templates select="." mode="toc-xref"/>
      </block>
    </list-item-body>
  </list-item>
</xsl:template>

<xsl:template match="section">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="preambule">
  <xsl:variable name="id">
    <xsl:call-template name="get-id"/>
  </xsl:variable>
  <block id="{$id}">
    <xsl:if test="not(title)">
      <block xsl:use-attribute-sets="verylarge-title-font">
	<xsl:attribute name="space-after">5pt</xsl:attribute>
	<xsl:attribute name="space-before">10pt</xsl:attribute>
	<xsl:text>Préambule</xsl:text>
      </block>
    </xsl:if>
    <xsl:apply-templates/>
  </block>
</xsl:template>

<xsl:template match="book/title|section/title|preambule/title">
  <block xsl:use-attribute-sets="verylarge-title-font">
    <xsl:attribute name="space-after">5pt</xsl:attribute>
    <xsl:attribute name="space-before">10pt</xsl:attribute>
    <xsl:apply-templates/>
  </block>
</xsl:template>

<xsl:template match="poem/title">
  <block xsl:use-attribute-sets="large-title-font">
    <xsl:attribute name="space-after">5pt</xsl:attribute>
    <xsl:attribute name="space-before">10pt</xsl:attribute>
    <xsl:apply-templates/>
  </block>
</xsl:template>

<xsl:template match="nda">
  <block border="solid" padding="5mm"
    font-size="90%" font-style="italic"
    space-before="15mm" space-before.conditionality="discard"
    space-after="15mm" space-after.conditionality="discard"
    margin="5mm">
    <xsl:apply-templates/>
  </block>
</xsl:template>

<xsl:template match="para">
  <block xsl:use-attribute-sets="standard-block">
    <xsl:apply-templates/>
  </block>
</xsl:template>

<!-- dialog template -->
<xsl:template match="dialog">
  <block xsl:use-attribute-sets="standard-block" start-indent="1cm">
    <xsl:apply-templates/>
  </block>
</xsl:template>
<xsl:template match="cite">
  <block xsl:use-attribute-sets="standard-block" font-style="italic">
    <xsl:text>"</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>"</xsl:text>
  </block>
</xsl:template>

<xsl:template match="citation">
  <block xsl:use-attribute-sets="standard-block" font-style="italic"
         font-size="75%" margin-left="4in">
    <xsl:apply-templates/>
  </block>
</xsl:template>

<xsl:template match="poem">
  <block xsl:use-attribute-sets="standard-block">
    <xsl:attribute name="id">
      <xsl:value-of select="../@id"/>
    </xsl:attribute>
    <xsl:apply-templates/>
  </block>
</xsl:template>

<xsl:template match="strophe">
  <block xsl:use-attribute-sets="standard-block">
    <xsl:apply-templates/>
  </block>
</xsl:template>

<xsl:template match="verse">
  <block><xsl:apply-templates/></block>
</xsl:template>

<xsl:template match="cue">
  <block xsl:use-attribute-sets="standard-block" text-indent="0pt">
  <xsl:apply-templates/>
  </block>
</xsl:template>
<xsl:template match="caracter">
  <inline font-weight="bold">
    <xsl:apply-templates/>
  </inline>
  <xsl:text>: </xsl:text>
</xsl:template>
<xsl:template match="cue/para">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="poetry|section" mode="toc-xref">
  <xsl:variable name="id">
    <xsl:call-template name="get-id"/>
  </xsl:variable>
    <basic-link internal-destination="{$id}">
      <xsl:value-of select="descendant::title[1]"/>
      <leader leader-pattern="dots" leader-length.maximum="254mm"/>
      (<page-number-citation ref-id="{$id}"/>)
    </basic-link>
</xsl:template>

<xsl:template match="list[@role='toc']/item/xref">
  <xsl:variable name="linkend" select="@linkend"/>
  <xsl:apply-templates mode="toc-xref" select="//*[@id=$linkend]"/>
</xsl:template>

<xsl:template match="xref">
  <xsl:variable name="linkend" select="@linkend"/>
  <xsl:variable name="linkterm">
    <xsl:choose>
      <xsl:when test="@linkterm"><xsl:value-of select="@linkterm"/></xsl:when>
      <xsl:otherwise><xsl:value-of select="@linkend"/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
    <basic-link internal-destination="{$linkend}">
      <xsl:apply-templates mode="xref" select="//*[@id=$linkterm]"/>
    </basic-link>
</xsl:template>
    
<xsl:template match="poetry|section" mode="xref">
  <xsl:value-of select="descendant::title[1]"/>
</xsl:template>

</xsl:stylesheet>