<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/pool/xslt_ht.xslt" type="application/xml"?>
<xsl:stylesheet
  xmlns:d = "http://herbaer.de/xmlns/20051201/doc"
  xmlns:p = "http://herbaer.de/xmlns/20200528/ph"
  xmlns:v = "http://herbaer.de/xmlns/20200528/d"
  xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
  xmlns:xl = "http://www.w3.org/1999/xlink"
  version = "1.0"
  exclude-result-prefixes = "d p v xl"
>
<!--
  Werte in eine XHTML-Vorlage einsetzen
  2020-05-28 Herbert Schiemann <h.schiemann@herbaer.de>
  Borkener Str. 167, 46284 Dorsten, Germany
  GPL Version 2 oder neuer
-->
<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>values.xslt</title>
  <subtitle>Werte in eine XHTML-Vorlage einsetzen</subtitle>
  <date>2020-05-28</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<d:para>
Prefix des Pfades der Datenquellen (CGI-Skripte)
</d:para>
<xsl:param name="g_cgiprefix" select="'/cgi-bin/'"/>

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

<xsl:template match="/">
  <xsl:apply-templates select="* | processing-instruction()"/>
</xsl:template>

<d:para>
Elemente werden in einen Einsetzungs-Kontext gesetzt
</d:para>
<xsl:template match="*">
  <!-- Kontext -->
  <xsl:param name="ct"/>
  <xsl:copy>
    <xsl:choose>
      <xsl:when test="@p:s">
        <xsl:variable name="p" select="concat ($g_cgiprefix, @p:s)"/>
        <xsl:apply-templates select="@* | * | processing-instruction() | text()">
          <xsl:with-param name="ct" select="document($p)/v:d"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="@p:g">
        <xsl:variable name="k" select="@p:g"/>
        <xsl:variable name="t" select="."/>
        <xsl:for-each select="$ct/v:g[@k=$k]/v:d">
          <xsl:apply-templates select="$t" mode="d">
            <xsl:with-param name="ct" select="."/>
          </xsl:apply-templates>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="@* | * | processing-instruction() | text()">
          <xsl:with-param name="ct" select="$ct"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:copy>
</xsl:template>

<d:para>
Ein Element mit Daten eines Satzes evtl. wiederholt füllen
</d:para>
<xsl:template match="*" mode="d">
  <xsl:param name="ct"/>
  <xsl:copy>
    <xsl:apply-templates select="@* | processing-instruction() | text() | *">
      <xsl:with-param name="ct" select="$ct"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<d:para>
Attribute, Verarbeitungsanweisungen und Text werden kopiert.
</d:para>
<xsl:template match="@* | processing-instruction() | text()">
  <xsl:copy-of select="."/>
</xsl:template>

<d:para>
Kontext-Attribute werden entfernt.
</d:para>
<xsl:template match="@p:*"/>

<d:para>
Platzhalter werden durch ihre Werte ersetzt.
</d:para>
<xsl:template match="p:i">
  <xsl:param name="ct"/>
  <xsl:variable name="s" select="."/>
  <xsl:apply-templates select="$ct/v:i[@k=$s]"/>
</xsl:template>

<d:para>
Daten werden eingesetzt.
</d:para>
<xsl:template match="v:i">
  <xsl:apply-templates select="* | processing-instruction() | text()"/>
</xsl:template>

</xsl:stylesheet>
