<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="4.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  xmlns:math="http://www.w3.org/2005/xpath-functions/math"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
  xmlns:tm="http://www.datenverdrahten.de/tm"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="#all"
  expand-text="yes">

  <!-- by T. Meinike 11/22 -->

  <xsl:output method="xml" version="1.0" html-version="5" encoding="UTF-8"
    indent="yes" include-content-type="no" omit-xml-declaration="yes"/>

  <xsl:template name="xsl:initial-template">

    <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html>&#xA;</xsl:text>
    <html lang="de">
      <head>
        <meta charset="UTF-8"/>
        <title>for member</title>
        <style>
          * {{ font-family: sans-serif; }}
          table, th, td {{ border-collapse: collapse; border: 1px solid #000; padding: 0.5em; font-size: 1.1em; }}
          th {{ color: #00C; background-color: #EEE; }}
          td {{ text-align: right; }}
          p {{ font-weight: bold; color: #090; background-color: #FFF; margin-bottom: 1.5em; }}
          h2 {{ color: #333; background-color: #FFF; margin: 0.5em 0; }}
        </style>
      </head>
      <body>
        <h1>for member</h1>
        <!-- Ergebnis als Sequence, nicht als Array! -->

        <!-- Beispiel mit Zeichen(ketten) -->
        <xsl:variable name="b_arr" select="[('e','b','c','a','d'), ('z','x','y')]" as="array(*)"/>
        <xsl:variable name="b_seq" select="for member $m in $b_arr return fn:string-join(fn:sort($m), '')" as="xs:string*"/>
        <p><xsl:value-of select="$b_seq" separator=" | "/></p>

        <!-- Beispiel mit Zahlenwerten -->
        <xsl:variable name="d_arr" select="[(1,2,3,4,5), (10,20,30), (23,42)]" as="array(*)"/>
        <xsl:variable name="s_seq" select="for member $m in $d_arr return fn:sum($m)" as="xs:decimal*"/>
        <xsl:variable name="a_seq" select="for member $m in $d_arr return fn:avg($m)" as="xs:decimal*"/>

        <table>
          <tr>
            <th>Daten</th><th>Summe</th><th>Mittelwert</th>
          </tr>
          <xsl:for-each select="1 to array:size($d_arr)">
            <xsl:variable name="i" select="fn:position()" as="xs:integer"/>
            <tr>
              <td><xsl:value-of select="($d_arr($i))" separator=","/></td>
              <td>{$s_seq[$i]}</td>
              <td>{$a_seq[$i]}</td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>

  </xsl:template>

</xsl:stylesheet>