<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/pool/xslt_ht.xslt" type="application/xml"?>
<xsl:stylesheet
  xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
  xmlns:d = "http://herbaer.de/xmlns/20051201/doc"
  xmlns:ht = "http://www.w3.org/1999/xhtml"
  xmlns:xl = "http://www.w3.org/1999/xlink"
  version = "1.0"
  exclude-result-prefixes = "d ht xl"
>

<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>xhtml_minimize_index.xslt</title>
  <subtitle>Datei index.xhtml "minimieren"</subtitle>
  <date>2012-09-14</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<xsl:include href="/pool/xhtml_minimize.xslt"/>

<d:para>
Leere <d:tag>a</d:tag>-Elemente nur mit einem id-Attribut entfernen
</d:para>
<xsl:template match="ht:a[string-length (.) = 0 and count (./@*) = 1 and @id]"/>

<d:para>
Attribut <d:code>a/@target</d:code> entfernen, wenn nicht "_blank"
</d:para>
<xsl:template match="ht:a/@target [.!='_blank']"/>

<d:para>
Einziges Kind-Element <d:code>li/p</d:code> entfernen
</d:para>
<xsl:template match="ht:li[count (*)=1]/ht:p">
  <xsl:apply-templates/>
</xsl:template>

<!--
Entfernen der code-Elemente erschwert die Übersetzung - 2020-09-24
<d:para>
  <d:code>code</d:code> - Elemente in Überschriften entfernen
</d:para>
<xsl:template match = "ht:h1[count (*)=1]/ht:code">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match = "ht:h2[count (*)=1]/ht:code">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match = "ht:h3[count (*)=1]/ht:code">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match = "ht:h4[count (*)=1]/ht:code">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match = "ht:h5[count (*)=1]/ht:code">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match = "ht:h6[count (*)=1]/ht:code">
  <xsl:apply-templates/>
</xsl:template>
-->

<d:para>
<d:tag>span</d:tag>-Elemente ohne unmittelbaren Text-Inhalt mit genau einem Kind-Element
werden entfernt.
</d:para>
<xsl:template match="ht:span[count (*) = 1 and not (text())]">
  <xsl:apply-templates/>
</xsl:template>

<d:para>
<d:tag>blockquote</d:tag>-Elemente mit genau einem Kind-Element
ohne unmittelbaren Text-Inhalt werden entfernt.
</d:para>
<xsl:template
  match = "
    ht:blockquote
    [count (*) = 1 and not (text() [string-length (normalize-space (.)) &gt; 0])]
  "
>
  <xsl:apply-templates/>
</xsl:template>

<d:para>
Die einzigen Kindelemente von
<d:tag class="element">blockquote</d:tag>-Elementen ohne
<d:tag class="attribute">class</d:tag>-Attribut bekommen das
Attribut
<d:tag class="attribute">class</d:tag> =
<d:tag class="attvalue">quote</d:tag>.
</d:para>
<xsl:template match="ht:blockquote/ht:* [count (../ht:*) = 1 and not (@class)]">
  <xsl:copy>
    <xsl:attribute name="class">quote</xsl:attribute>
    <xsl:apply-templates select="@* | * | text()"/>
  </xsl:copy>
</xsl:template>

<d:para>
Bestimmte
<d:tag class="element">span</d:tag>-Elemente werden entfernt.
</d:para>
<xsl:template
  match = "
    ht:span[
    @class = 'personname'
    or @class = 'firstname'
    or @class = 'honorific'
    or @class = 'surname'
    or @class = 'country' ]
  "
>
  <xsl:apply-templates/>
</xsl:template>

<d:para>
Einige <d:tag class="attribute">class</d:tag>-Attribute werden entfernt.
</d:para>
<xsl:template match="@class [. = 'address']"/>
<xsl:template match="@class [. = 'blockquote']"/>
<xsl:template match="@class [. = 'code']"/>
<xsl:template match="@class [. = 'command']"/>
<xsl:template match="@class [. = 'email']"/>
<xsl:template match="@class [. = 'filename']"/>
<xsl:template match="@class [. = 'itemizedlist']"/>
<xsl:template match="@class [. = 'link']"/>
<xsl:template match="@class [. = 'listitem']"/>
<xsl:template match="@class [. = 'literal']"/>
<xsl:template match="@class [. = 'person']"/>
<xsl:template match="@class [. = 'programlisting']"/>
<xsl:template match="@class [. = 'replaceable']"/>
<xsl:template match="@class [. = 'section']"/>
<xsl:template match="@class [. = 'sgmltag-element']"/>
<xsl:template match="@class [. = 'sgmltag-attribute']"/>
<xsl:template match="@class [. = 'title']"/>
<xsl:template match="@class [. = 'titlepage']"/>
<xsl:template match="@class [. = 'uri']"/>

<d:para>
<d:tag class="attribute">title</d:tag>-Attribute zu
<d:tag class="element">a</d:tag>-Elementen bleiben erhalten.
</d:para>
<xsl:template match="ht:a/@title">
  <xsl:copy-of select="."/>
</xsl:template>

<d:para>
Andere <d:tag class="attribute">title</d:tag>-Attribute werden entfernt.
</d:para>
<xsl:template match="@title"/>

<!--
xsltproc erkennt anscheinend eine zusammengesetzte Bedingung nicht als Spezialisierung
einer importierten Vorlage:

<xsl:template match = "ht:div [count (*) &lt;= 1 and @id != 'div_links']">
hat nicht Vorrang vor der importierten Vorlage
<xsl:template match = "ht:div">
-->
<d:para>
"Umhüllende" <d:tag class="element">div</d:tag>-Elemente mit genau einem Kind-Element
werden entfernt.
Ausgenommen ist die Verweisliste mit der ID <d:tag class="attvalue">div_links</d:tag>.
</d:para>
<xsl:template match="ht:div [count (*) &lt;= 1]">
  <xsl:choose>
    <xsl:when test="@id = 'div_links'">
      <xsl:copy>
        <xsl:choose>
          <xsl:when test="text() [string-length (normalize-space(.)) &gt; 0]">
            <xsl:apply-templates select="@*|*|text()"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="@*|*"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:copy>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="*"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<d:para>
Umhüllende <d:tag class="element">em</d:tag>-Elemente werden entfernt
</d:para>
<xsl:template match="ht:em [count (*) = 1 and not (text()[string-length(.) &gt; 0])]">
  <xsl:apply-templates select="*"/>
</xsl:template>

<d:para>
Verschachtelte <d:tag class="element">code</d:tag>-Elemente werden entfernt
</d:para>
<xsl:template match="ht:code [ancestor::ht:code or ancestor::ht:pre]">
  <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
