<?xml version="1.0"?>
<?xml-stylesheet href="/pool/xslt_ht.xslt" type="application/xml"?>
<xsl:stylesheet
  xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
  xmlns:is = "http://herbaer.de/xmlns/20080705/imgshow"
  xmlns:sl = "http://herbaer.de/xmlns/20100205/imgselect"
  xmlns:d = "http://herbaer.de/xmlns/20051201/doc"
  xmlns:ht = "http://www.w3.org/1999/xhtml"
  xmlns = "http://herbaer.de/xmlns/20080705/imgshow"
  exclude-result-prefixes = "d is sl"
  version = "1.0"
>
<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>imgshow_web.xslt</title>
  <subtitle>WWW-Version einer "Bildergeschichte"</subtitle>
  <date>2014-05-23</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<d:section xmlns="http://herbaer.de/xmlns/20051201/doc" role="stylesheet">
<para>
Die Bildergeschichten im WWW sind
vereinfachte Versionen der Bildergeschichten im Katalog.
Entfernt werden
</para>
<simplelist>
<member>Katalog-Abschnitte (Bilderlisten),</member>
<member>Verweise auf Puppen, Perücken, Kleider und andere Bildergeschichten,</member>
<member>Verweise auf Bilder, die nicht ausgewählt sind, und</member>
<member><tag class="element">meta</tag>-Elemente.</member>
</simplelist>
</d:section><!-- role = 'stylesheet' -->

<d:para>Dateipfad der Bildauswahl-Datei</d:para>
<xsl:param name="p_selfile" select="''"/>

<d:para>Präfix für Verweise auf eine Bildergeschichte</d:para>
<xsl:param name="p_prf_story" select="'../s'"/>

<d:para>Suffix für Verweise auf eine Bildergeschichte</d:para>
<xsl:param name="p_sfx_story" select="'/story.xml'"/>

<d:para>Suffix für Verweis auf das Vorschaubild einer Bildergeschichte</d:para>
<xsl:param name="p_sfx_thumbnail" select="'/thumbnail.jpg'"/>

<d:para>Präfix der absoluten URL einer Bildergeschichte</d:para>
<xsl:param name="p_absprf_story" select="'http://kleider.herbaer.de/s'"/>

<d:para>
Diese Sprachkennung wird eingesetzt,
wenn das Wurzelelement der  Quelldatei keine Sprachkennung enthält.
</d:para>
<xsl:param name="p_lang" select="'de-DE'"/>

<d:para>Die Kennungen der ausgewählten Bilder</d:para>
<xsl:variable name="g_selimgs">
  <xsl:if test="string-length ($p_selfile) &gt; 0">
    <xsl:for-each select="document($p_selfile)//sl:images/sl:image[. &gt; 0]">
      <xsl:value-of select="concat (',', @src)"/>
    </xsl:for-each>
    <xsl:text>,</xsl:text>
  </xsl:if>
</xsl:variable>

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

<d:para>Wurzel mit Verarbeitungsanweisungen verarbeiten</d:para>
<xsl:template match="/">
  <xsl:apply-templates select="processing-instruction() | text() | *"/>
</xsl:template>

<d:para>Sprachkennung zum Wurzelelement hinzufügen</d:para>
<xsl:template match="is:document [not (@xml:lang)]">
  <xsl:copy>
    <xsl:attribute name="xml:lang">
      <xsl:value-of select="$p_lang"/>
    </xsl:attribute>
    <xsl:apply-templates select="@* | * | text()"/>
  </xsl:copy>
</xsl:template>

<d:para>Verarbeitungsanweisungen werden kopiert</d:para>
<xsl:template match="processing-instruction()">
  <xsl:copy-of select="."/>
</xsl:template>

<d:para>
Elemente und Attribute werden kopiert,
soweit es keine andere Vorlage gibt
</d:para>
<xsl:template match="* | @*">
  <xsl:copy>
    <xsl:apply-templates select="@* | * | text()"/>
  </xsl:copy>
</xsl:template>

<d:para>Nur ausgewählte Bildverweise werden übernommen</d:para>
<xsl:template match="is:jpg">
  <xsl:choose>
    <xsl:when test="contains ($g_selimgs, concat (',', @src, ','))">
      <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
      </xsl:copy>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<d:para>Das Attribut <d:tag class="attribute">kleid</d:tag> wird entfernt.</d:para>
<xsl:template match="@kleid"/>

<d:para>Katalog-Abschnitte werden ausgenommen</d:para>
<xsl:template match="is:section[@role = 'cat']"/>
<xsl:template match="is:p[@role = 'cat']"/>

<d:para>"Private" Abschnitte werden ebenfalls ausgenommen</d:para>
<xsl:template match="is:section[@role = 'private']"/>
<xsl:template match="is:p[@role = 'private']"/>

<d:para>
Zur Kennung der Bildergeschichte werden RDF-Daten eingefügt,
wichtig ist hier für Suchmaschinen der Verweis auf ein Vorschaubild.
</d:para>
<xsl:template match="is:meta [@name = 'story']">
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://schema.org/"
  >
    <WebPage>
      <url><xsl:value-of select="concat($p_absprf_story, ., $p_sfx_story)"/></url>
      <thumbnailUrl>
        <xsl:value-of select="concat($p_absprf_story, ., $p_sfx_thumbnail)"/>
      </thumbnailUrl>
    </WebPage>
  </rdf:RDF>
</xsl:template>

<d:para>Andere <d:tag class="element">meta</d:tag>-Elemente werden ausgenommen</d:para>
<xsl:template match="is:meta"/>

<d:para>Spezielle Verweise werden entfernt</d:para>
<xsl:template match="is:puppe | is:peruecke | is:kleid">
  <xsl:apply-templates/>
</xsl:template>

<d:para>
Verweis auf einen Abschnitt oder ein Bild innerhalb der Geschichte.
Die Abschnittsnummern ändern sich.
</d:para>
<xsl:template match="is:sect">
  <!-- die alte Abschnitts-Nummer -->
  <xsl:variable name="sn">
    <xsl:choose>
      <xsl:when test="not (contains (@ref, '_'))">
        <xsl:value-of select="@ref"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="substring-before (@ref, '_')"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="role" select="//is:section [number($sn)]/@role"/>
  <xsl:choose>
    <xsl:when test="$role = 'cat' or $role = 'private'">
      <xsl:apply-templates/>
    </xsl:when>
    <xsl:otherwise>
      <!-- die neue Abschnitts-Nummer -->
      <xsl:variable
        name = "nsn"
        select = "
          count ( //is:section
          [position() &lt;= $sn and not (@role = 'cat' or @role = 'private')] )
        "
      />
      <sect>
        <xsl:attribute name="ref">
          <xsl:value-of select="$nsn"/>
          <xsl:if test="contains (@ref, '_')">
            <xsl:value-of select="concat ('_', substring-after (@ref, '_'))"/>
          </xsl:if>
        </xsl:attribute>
        <xsl:apply-templates/>
      </sect>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
