<?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>Other XPath 4.0 proposed extensions</title>
        <style>* {{ font-family: sans-serif; }}</style>
      </head>
      <body>
        <h1>Other XPath 4.0 proposed extensions</h1>

        <h2>Ternary Conditions</h2>
        <xsl:variable name="w" as="xs:string" select="23 lt 42 ?? 'ok' !! 'nicht ok'"/>
        <p>{$w}</p> <!-- ok -->
      
        <h2>Otherwise operator</h2>
        <xsl:variable name="a" as="xs:positiveInteger*" select="10"/>
        <!-- <xsl:variable name="b" as="xs:positiveInteger*" select="5"/> -->
        <xsl:variable name="b" as="xs:positiveInteger*" select="()" />
        <p>{$a div $b otherwise 2}</p> <!-- bedeutet: $a div ($b otherwise 2) -->
        <!-- auf Elementebene wenn erster Teil leer ist, dann lies zweiten Teil: p[@id='speziell'] otherwise p[1] -->

        <h2>For-member expressions</h2>
        <p>{for member $m in [(3,5,6), (8,12)] return sum($m)}</p> <!-- (14, 20) -->

        <p>{let $json := '[{"x":1, "y":"one"}, {"x":2, "y":"two"}]'
            return for member $map in parse-json($json) return $map?y}</p> <!-- ("one", "two") -->
      
        <h2>Simple inline functions</h2>        
        <xsl:variable name="f" select="function($x, $y){$x + $y}"/>
        <p>{$f(23, 42)}</p> <!-- 65 -->
      
        <!-- Thin arrow notation -->
        <xsl:variable name="g" select="->($x, $y){$x + $y}"/>
        <p>{$g(23, 42)}</p> <!-- 65 -->
      
        <!-- Underscore functions -->
        <!-- function($a1 as item()*, $a2 as item()*) as item()* {$a1 + $a2}
             This feature seems likely to be dropped, but it remains available in Saxon 11.
        -->
        <xsl:variable name="h" select="_{$1 * $2}"/>
        <p>{$h(23, 42)}</p> <!-- 966 -->
      </body>
    </html>

  </xsl:template>

</xsl:stylesheet>