<?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:d = "http://herbaer.de/xmlns/20051201/doc"
  xmlns:sl = "http://herbaer.de/xmlns/20100205/imgselect"
  xmlns:is = "http://herbaer.de/xmlns/20080705/imgshow"
  xmlns = "http://herbaer.de/xmlns/20100205/imgselect"
  exclude-result-prefixes = "xsl d sl is"
  version = "1.0"
>

<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>imgselect_adjust.xslt</title>
  <subtitle>Bildauswahldatei an die Bildergeschichte im Web anpassen</subtitle>
  <date>2013-09-07</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<d:para>
Das Tagesdatum wird als letztes Änderungsdatum zu neuen Bildergeschichten eingetragen
</d:para>
<xsl:param name="p_today" select="'2012-07-11'"/>

<d:para>
Pfad der Bildergeschichte
</d:para>
<xsl:param
  name = "p_story"
  select = "
    concat (
    '../../docroot/s',
    substring-before (substring-after (/sl:imgselect/sl:meta/sl:filename,
    '/imgselect_'),
    '.xml'),
    '/story.xml' )
  "
/>

<d:para>
Wurzelelement der Bildergeschichte
</d:para>
<xsl:variable name="g_storyroot" select="document($p_story)/is:document"/>

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

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

<d:para>
Auswahl eines einzelnen Bildes abgleichen
</d:para>
<xsl:template match="sl:image">
  <xsl:variable name="iid" select="@src"/>
  <xsl:choose>
    <xsl:when test="$g_storyroot//is:jpg [@src = $iid]">
      <xsl:choose>
        <xsl:when test=". = 0 or string-length(.) = 0">
          <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:text>1</xsl:text>
          </xsl:copy>
          <xsl:comment>
            <xsl:value-of select="concat(' ge&#xE4;ndert ', $p_today, ' ')"/>
          </xsl:comment>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:choose>
        <xsl:when test=". = 0 or string-length(.) = 0">
          <xsl:copy-of select="."/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:text>0</xsl:text>
          </xsl:copy>
          <xsl:comment>
            <xsl:value-of select="concat(' ge&#xE4;ndert ', $p_today, ' ')"/>
          </xsl:comment>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<d:para>
Andere Elemente und Attribute werden kopiert
</d:para>
<xsl:template match="* | @*">
  <xsl:copy>
    <xsl:apply-templates select="* | @*| text()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
