view software/mpdl-services-new/mpiwg-mpdl-cms/build/classes/de/mpg/mpiwg/berlin/mpdl/cms/transform/toc.xsl @ 25:e9fe3186670c default tip

letzter Stand eingecheckt
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 21 May 2013 10:19:32 +0200
parents
children
line wrap: on
line source

<?xml version="1.0"?>

<xsl:stylesheet 
  version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="xsl xlink xhtml"
>

<xsl:output method="xml" encoding="utf-8" indent="yes"/>

<xsl:template match="/">
  <xsl:variable name="toc" select="//*:div[@type = 'section' or @type = 'chapter' or @type = 'part']"/>
  <xsl:variable name="figures" select="//*:figure"/>
  <xsl:variable name="notes" select="//*:note|//*:handwritten"/>
  <xsl:variable name="pages" select="//*:pb"/>
  <xsl:variable name="places" select="//*:place"/>
  <list>
    <xsl:if test="not(empty($toc))">
      <list type ="toc">
        <xsl:attribute name="count"><xsl:value-of select="count($toc)"/></xsl:attribute>
        <head>Table of contents</head>
        <xsl:apply-templates select="$toc"/>
      </list>
    </xsl:if>
    <xsl:if test="not(empty($figures))">
      <list type="figures">
        <xsl:attribute name="count"><xsl:value-of select="count($figures)"/></xsl:attribute>
        <head>Figures</head>
        <xsl:apply-templates select="$figures"/>
      </list>
    </xsl:if>
    <xsl:if test="not(empty($notes))">
      <list type="notes">
        <xsl:attribute name="count"><xsl:value-of select="count($notes)"/></xsl:attribute>
        <head>Notes</head>
        <xsl:apply-templates select="$notes"/>
      </list>
    </xsl:if>
    <xsl:if test="not(empty($pages))">
      <list type="pages">
        <xsl:attribute name="count"><xsl:value-of select="count($pages)"/></xsl:attribute>
        <head>Pages</head>
        <xsl:apply-templates select="$pages"/>
      </list>
    </xsl:if>
    <xsl:if test="not(empty($places))">
      <list type="places">
        <xsl:attribute name="count"><xsl:value-of select="count($places)"/></xsl:attribute>
        <head>Places</head>
        <xsl:apply-templates select="$places"/>
      </list>
    </xsl:if>
  </list>
</xsl:template>

<xsl:template match="*:figure">
  <xsl:variable name="page" select="count(./preceding::*:pb)"/>
  <xsl:variable name="number" select="@number"/>
  <item>
    <xsl:if test="not(empty($number))"><xsl:attribute name="n"><xsl:value-of select="$number"/></xsl:attribute></xsl:if>
    <xsl:apply-templates select="*:caption"/>
    <xsl:apply-templates select="*:description"/>
    <xsl:apply-templates select="*:variables"/>
    <xsl:if test="not(empty($page))"><ref><xsl:value-of select="$page"/></ref></xsl:if>
  </item>
</xsl:template>

<xsl:template match="*:caption"><xsl:value-of select="' '"/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="*:description">
  <xsl:apply-templates/><xsl:value-of select="' '"/>
</xsl:template>

<xsl:template match="*:variables">
  <xsl:apply-templates/><xsl:value-of select="' '"/>
</xsl:template>

<xsl:template match="*:note|*:handwritten">
  <xsl:variable name="page" select="count(./preceding::*:pb)"/>
  <xsl:variable name="number" select="@number"/>
  <xsl:variable name="position" select="@position"/>
  <xsl:variable name="type">
    <xsl:choose>
      <xsl:when test="name() = 'note'"><xsl:value-of select="'printed'"/></xsl:when>
      <xsl:when test="name() = 'handwritten'"><xsl:value-of select="'handwritten'"/></xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <item>
    <xsl:if test="not(empty($type))"><xsl:attribute name="type"><xsl:value-of select="$type"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty($position))"><xsl:attribute name="position"><xsl:value-of select="$position"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty($number))"><xsl:attribute name="n"><xsl:value-of select="$number"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty($page))"><ref><xsl:value-of select="$page"/></ref></xsl:if>
  </item>
</xsl:template>

<xsl:template match="*:place">
  <xsl:variable name="page" select="count(./preceding::*:pb)"/>
  <xsl:variable name="id" select="@id"/>
  <item>
    <xsl:if test="not(empty($id))"><xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute></xsl:if>
    <content><xsl:apply-templates/></content>
    <xsl:if test="not(empty($page))"><ref><xsl:value-of select="$page"/></ref></xsl:if>
  </item>
</xsl:template>

<xsl:template match="*:div">
  <xsl:variable name="level"><xsl:number level="multiple" count="*:div[@type = 'section' or @type = 'chapter' or @type = 'part']" format="1."/></xsl:variable>
  <xsl:variable name="depth" select="string-length(replace($level, '[^\\.]', ''))"/>
  <xsl:variable name="pb" select="./preceding::*:pb[1]"/>
  <xsl:variable name="o" select="$pb/@o"/>
  <xsl:variable name="oNorm" select="$pb/@o-norm"/>
  <xsl:variable name="page" select="count(./preceding::*:pb)"/>
  <item>
    <xsl:if test="not(empty($level))"><xsl:attribute name="n"><xsl:value-of select="$level"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty($level))"><xsl:attribute name="lv"><xsl:value-of select="$depth"/></xsl:attribute></xsl:if>
    <xsl:apply-templates select="*:head"/>
    <xsl:if test="not(empty($page))">
      <ref>
        <xsl:if test="not(empty($o))"><xsl:attribute name="o"><xsl:value-of select="$o"/></xsl:attribute></xsl:if>
        <xsl:if test="not(empty($oNorm))"><xsl:attribute name="o-norm"><xsl:value-of select="$oNorm"/></xsl:attribute></xsl:if>
        <xsl:value-of select="$page"/>
      </ref>
    </xsl:if>
  </item>
</xsl:template>

<xsl:template match="*:head">
  <xsl:apply-templates/><xsl:value-of select="' '"/>
</xsl:template>

<xsl:template match="*:pb">
  <xsl:variable name="page" select="count(./preceding::*:pb) + 1"/>
  <item>
    <xsl:attribute name="n"><xsl:value-of select="$page"/></xsl:attribute>
    <xsl:if test="not(empty(@o))"><xsl:attribute name="o"><xsl:value-of select="@o"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty(@o-norm))"><xsl:attribute name="o-norm"><xsl:value-of select="@o-norm"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty(@file))"><xsl:attribute name="file"><xsl:value-of select="@file"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty(@facs))"><xsl:attribute name="file"><xsl:value-of select="@facs"/></xsl:attribute></xsl:if>
  </item>
</xsl:template>

</xsl:stylesheet>