<?xml version='1.0' encoding='UTF-8'?>

<Properties version="4.1">
	<Property name="ErrorSuppression" type="Boolean">false</Property>
	<Property name="IsModuleTemplate" type="Boolean">false</Property>
	<Property name="xslt.base64Zipped">true</Property>
	<Property name="xslt.ignoreInput">false</Property>
	<Property name="xslt.params" type="List">
		<Property name="var.session">var.session</Property>
	</Property>
	<Property name="xslt.saveAtServer">true</Property>
	<Property name="xslt.source"></Property>
	<Property name="xslt.sourceVariables" type="Map" />
	<Property name="xslt.stylesheet" type="XmlDocument">&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:am="http://www.bosch-si.com/2013/AM" xmlns:isxp="java:com.inubit.ibis.xsltext.ISFunctions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:json="json:json" exclude-result-prefixes="#all" version="2.0">&lt;xsl:param name="var.session" as="element()"/>&lt;xsl:variable name="databaseType" as="element()" select="$var.session/configuration/api/database/type"/>
  &lt;xsl:output method="xml" encoding="UTF-8"/>

  &lt;xsl:function name="am:booleanToDB">
    &lt;xsl:param name="value"/>
    &lt;xsl:value-of select="if (xs:string($value) = ('true', '1')) then '1' else '0'"/>
  &lt;/xsl:function>



  &lt;xsl:function name="am:escapeString">
    &lt;xsl:param name="value"/>

    &lt;xsl:value-of select="replace($value, &amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;)"/>
  &lt;/xsl:function>&lt;xsl:function name="am:multilineStringToDB">&lt;xsl:param name="value"/>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:choose>&lt;xsl:when test="string-length($value) &amp;gt; 3000">&lt;xsl:value-of select="concat(&amp;quot;CONVERT(NTEXT, N'&amp;quot;, replace(replace(substring($value, 1, 3000), &amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;), &amp;quot;\n&amp;quot;, &amp;quot;') + convert(varchar(10), 0xA) + CONVERT(NTEXT, N'&amp;quot;), &amp;quot;') + &amp;quot;, am:multilineStringToDB(substring($value, 3001)))"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="concat(&amp;quot;N'&amp;quot;, replace(replace($value, &amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;), &amp;quot;\n&amp;quot;, &amp;quot;' + convert(varchar(10), 0xA) + N'&amp;quot;), &amp;quot;'&amp;quot;)"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:value-of select="concat('E', replace(replace(am:stringToDB($value), '\\', '\\\\'), '\n', '\\n'))">&lt;!--"Escape" string syntax for newlines-->&lt;/xsl:value-of>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:choose>&lt;xsl:when test="string-length($value) &amp;gt; 3000">&lt;xsl:value-of select="concat(&amp;quot;to_clob('&amp;quot;, replace(replace(substring($value, 1, 3000), &amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;), &amp;quot;\n&amp;quot;, &amp;quot;') || chr(10) || to_clob('&amp;quot;), &amp;quot;')&amp;quot;), ' || ', am:multilineStringToDB(substring($value, 3001))"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="concat(&amp;quot;to_clob('&amp;quot;, replace(replace($value, &amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;), &amp;quot;\n&amp;quot;, &amp;quot;') || chr(10) || to_clob('&amp;quot;), &amp;quot;')&amp;quot;)"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:function>

  &lt;xsl:function name="am:escapeLikeString">
    &lt;xsl:param name="value"/>
    &lt;xsl:value-of select="replace(replace(am:escapeString($value), '%', '\\%'), '_', '\\_')"/>
  &lt;/xsl:function>

  &lt;xsl:function name="am:escapeContainsString">
    &lt;xsl:param name="value"/>
    &lt;xsl:value-of select="replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(am:escapeString($value), '\\', '\\\\'), ',', '\\,'), '&amp;amp;', '\\&amp;amp;'), '=', '\\='), '\?', '\\?'), '\{', '\\{'), '\}', '\\}'), '\(', '\\('), '\)', '\\)'), '\[', '\\['), '\]', '\\]'), '-', '\\-'), ';', '\\;'), '~', '\\~'), '\|', '\\|'), '\$', '\\\$'), '!', '\\!'), '&amp;gt;', '\\&amp;gt;'), '\*', '\\*'), '%', '\\%'), '_', '\\_')"/>
  &lt;/xsl:function>

  

  &lt;xsl:function name="am:keyInAssetList">&lt;xsl:param name="var.key"/>
    &lt;xsl:param name="var.assets" as="element()*"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="not(exists($var.assets))">&lt;xsl:text> ( 0 = 1 )&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:text>(&lt;/xsl:text>&lt;xsl:value-of select="$var.key"/>&lt;xsl:text> in (&lt;/xsl:text>&lt;xsl:for-each select="$var.assets">&lt;xsl:choose>&lt;xsl:when test="position() mod 1000 = 0">&lt;xsl:text>) or &lt;/xsl:text>&lt;xsl:value-of select="$var.key"/>&lt;xsl:text> in (&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:when test="position() != 1">&lt;xsl:text>,&lt;/xsl:text>&lt;/xsl:when>&lt;/xsl:choose>&lt;xsl:value-of select="am:numberToDB(id)"/>&lt;xsl:value-of/>&lt;/xsl:for-each>&lt;xsl:text>))&lt;/xsl:text>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>


  &lt;/xsl:function>&lt;xsl:function name="am:comma">&lt;xsl:text>,&lt;/xsl:text>&lt;/xsl:function>&lt;xsl:function name="am:oracleXML">
    &lt;xsl:param name="var.root" as="element()"/>&lt;xsl:text>xmlelement(&lt;/xsl:text>&lt;xsl:value-of select="concat('&amp;quot;', name($var.root), '&amp;quot;')"/>&lt;xsl:choose>&lt;xsl:when test="exists($var.root/*)">&lt;xsl:text>,&lt;/xsl:text>&lt;xsl:for-each select="$var.root/*">&lt;xsl:value-of select="am:oracleXML(.)"/>&lt;xsl:if test="position() != last()">&lt;xsl:text>,&lt;/xsl:text>&lt;/xsl:if>&lt;/xsl:for-each>&lt;/xsl:when>&lt;xsl:when test="exists($var.root/text())">&lt;xsl:value-of select="concat(', ' , am:multilineStringToDB($var.root/text()))"/>&lt;/xsl:when>&lt;/xsl:choose>&lt;xsl:text>)&lt;/xsl:text>

    &lt;/xsl:function>&lt;xsl:function name="am:currentDateTimeForDB">&lt;xsl:value-of select="format-dateTime(adjust-dateTime-to-timezone(current-dateTime(), xs:dayTimeDuration('PT0H')), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001]Z')"/>&lt;/xsl:function>&lt;xsl:function name="am:checkFullTemplateAccess">&lt;xsl:param name="var.template" as="element()"/>&lt;xsl:if test="not($var.template/computedUse/read/* = $var.session/user/roles/*)">&lt;xsl:value-of select="error(xs:QName('error'), 'Access violation.')"/>&lt;/xsl:if>&lt;/xsl:function>&lt;xsl:function name="am:checkRestrictedTemplateAccess">&lt;xsl:param name="var.template" as="element()"/>&lt;xsl:if test="not($var.template/computedUse/(read | child)/* = $var.session/user/roles/*)">&lt;xsl:value-of select="error(xs:QName('error'), 'Access violation.')"/>&lt;/xsl:if>&lt;/xsl:function>&lt;xsl:function name="am:templateAccess">&lt;xsl:param name="var.template" as="element()"/>&lt;xsl:choose>&lt;xsl:when test="$var.template/computedUse/read/* = $var.session/user/roles/*">&lt;xsl:value-of select="'full'"/>&lt;/xsl:when>&lt;xsl:when test="$var.template/computedUse/child/* = $var.session/user/roles/*">&lt;xsl:value-of select="'restricted'"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="'none'"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:function>&lt;xsl:function name="am:maybeTemplateAccessLevel">&lt;xsl:param name="var.template" as="element()?"/>&lt;xsl:if test="exists($var.template)">&lt;accessLevel>&lt;xsl:value-of select="am:templateAccess($var.template)"/>&lt;/accessLevel>&lt;/xsl:if>&lt;/xsl:function>&lt;xsl:function name="am:attributeKeyToQName">

    &lt;xsl:param name="_"/>&lt;xsl:value-of select="replace(replace($_, '^[0-9-]', '_'), '[: !&amp;quot;#$%&amp;amp;*\(\)''+,/:;&amp;lt;=&amp;gt;?@\[\]^`\{\|\}~\\]', '_')"/>&lt;!--Aus historischen Gründen werden viele ASCII-Sonderzeichen erlaubt, aber als _ behandelt-->

  &lt;/xsl:function>&lt;!--NEU (für PostgreSQL)-->&lt;xsl:function name="am:orderAtTop" as="xs:boolean">&lt;xsl:sequence select="$databaseType = ('mssql', 'postgresql')"/>&lt;/xsl:function>&lt;xsl:function name="am:emptyResultQuery" as="xs:string">&lt;xsl:choose>&lt;xsl:when test="$databaseType = ('mssql', 'postgresql')">select 1 where 0 = 1&lt;/xsl:when>&lt;xsl:otherwise>select 1 from dual where 0 = 1&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:function>&lt;xsl:function name="am:queriesForCreate" as="element()*">&lt;xsl:param name="var.sequenceName"/>&lt;xsl:param name="var.queries" as="element()*"/>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;query properties="force" queryID="insert">&lt;value>&lt;xsl:text>DECLARE @NextID int ;  SET @NextID = NEXT VALUE FOR &lt;/xsl:text>&lt;xsl:value-of select="$var.sequenceName"/>&lt;xsl:text>; &lt;/xsl:text>&lt;xsl:for-each select="$var.queries">&lt;xsl:value-of select="value"/>&lt;xsl:text>;&lt;/xsl:text>&lt;/xsl:for-each>&lt;/value>&lt;/query>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:sequence select="$var.queries"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;query properties="force" queryID="id">&lt;value>&lt;xsl:value-of select="am:selectNewID($var.sequenceName)"/>&lt;/value>

      &lt;/query>&lt;/xsl:function>&lt;xsl:function name="am:nextID" as="xs:string">&lt;xsl:param name="var.sequenceName"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = ('mssql')"> @NextID&lt;/xsl:when>&lt;xsl:when test="$databaseType = ('postgresql')"> NEXTVAL(&lt;xsl:value-of select="am:stringToDB($var.sequenceName)"/>) &lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="$var.sequenceName"/>.NEXTVAL &lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:newIDValue" as="xs:string">&lt;xsl:param name="var.sequenceName"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = ('mssql')"> @NextID&lt;/xsl:when>&lt;xsl:when test="$databaseType = ('postgresql')"> CURRVAL(&lt;xsl:value-of select="am:stringToDB($var.sequenceName)"/>) &lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="$var.sequenceName"/>.CURRVAL &lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:selectNewID" as="xs:string">&lt;xsl:param name="var.sequenceName"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = ('mssql')">SELECT CAST(current_value AS int) as ID FROM sys.sequences WHERE name = &lt;xsl:value-of select="am:stringToDB($var.sequenceName)"/>&lt;/xsl:when>&lt;xsl:when test="$databaseType = ('postgresql')">SELECT CURRVAL(&lt;xsl:value-of select="am:stringToDB($var.sequenceName)"/>) ID&lt;/xsl:when>&lt;xsl:otherwise>SELECT &lt;xsl:value-of select="$var.sequenceName"/>.CURRVAL ID FROM DUAL&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:numberToDB" as="xs:string">&lt;xsl:param name="_"/>&lt;xsl:value-of select="xs:decimal($_)"/>&lt;/xsl:function>&lt;xsl:function name="am:stringToDB" as="xs:string">&lt;xsl:param name="_"/>&lt;xsl:value-of select="concat(&amp;quot;'&amp;quot;, replace($_, &amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;), &amp;quot;'&amp;quot;)"/>&lt;/xsl:function>&lt;xsl:function name="am:nodeFromDB" as="xs:string">&lt;xsl:param name="var.field"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = ('mssql', 'postgresql')">&lt;xsl:value-of select="concat(' ', $var.field, ' ')"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="concat(' ', $var.field, &amp;quot;.getBlobVal(nls_charset_id('UTF8')) &amp;quot;, replace($var.field, '.*[.]', ''), ' ')"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:timestampFromDB" as="xs:string">&lt;xsl:param name="var.field"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:text> format(&lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text>, 'yyyy-MM-dd"T"HH:mm:ss.fff"Z"') &lt;/xsl:text>&lt;xsl:value-of select="concat(' ', replace($var.field, '.*[.]', ''), ' ')"/>&lt;xsl:text> &lt;/xsl:text>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:text> to_char(&lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text>, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') &lt;/xsl:text>&lt;xsl:value-of select="concat(' ', replace($var.field, '.*[.]', ''), ' ')"/>&lt;xsl:text> &lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:text> to_char(cast(&lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text> as timestamp), 'YYYY-MM-DD"T"hh24:mi:ss.FF3"Z"') &lt;/xsl:text>&lt;xsl:value-of select="concat(' ', replace($var.field, '.*[.]', ''), ' ')"/>&lt;xsl:text> &lt;/xsl:text>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:timestampFromDB" as="xs:string">&lt;xsl:param name="var.field"/>&lt;xsl:param name="var.name"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:text> format(&lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text>, 'yyyy-MM-dd"T"HH:mm:ss.fff"Z"') &lt;/xsl:text>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:text> to_char(&lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text>, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') &lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:text> to_char(cast(&lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text> as timestamp), 'YYYY-MM-DD"T"hh24:mi:ss.FF3"Z"') &lt;/xsl:text>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;xsl:value-of select="concat(' ', $var.name)"/>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:timestampToDB" as="xs:string">&lt;xsl:param name="_"/>&lt;xsl:variable name="var.date" select="adjust-dateTime-to-timezone(xs:dateTime($_), xs:dayTimeDuration('PT0H'))"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:text> CONVERT(DATETIME2, &lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB(format-dateTime($var.date, '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001]Z'))"/>&lt;xsl:text>, 127) &lt;/xsl:text>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:text> timestamp &lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB(format-dateTime($var.date, '[Y0001]-[M01]-[D01] [H01]:[m01]:[s01].[f001]'))"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:text> to_timestamp(&lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB(format-dateTime($var.date, '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001]Z'))"/>&lt;xsl:text>, 'YYYY-MM-DD"T"hh24:mi:ss.FF3"Z"') &lt;/xsl:text>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:nodeToDB" as="xs:string">&lt;xsl:param name="var.root" as="element()"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:value-of select="concat(&amp;quot; CONVERT(XML, N'&amp;quot;,  replace(replace(isxp:serialize($var.root), '\n', '&amp;amp;#xA;'), &amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;), &amp;quot;', 2) &amp;quot;)"/>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:text> xmlparse(content &lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB(replace(isxp:serialize($var.root), '\n', '&amp;amp;#xA;'))"/>&lt;xsl:text>) &lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="am:oracleXML($var.root)"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:stringToNode" as="element()">&lt;xsl:param name="var.string"/>&lt;xsl:sequence select="if ($databaseType = ('mssql', 'postgresql')) then isxp:deserialize(string($var.string)) else isxp:deserialize(isxp:decode(string($var.string)))"/>&lt;/xsl:function>&lt;xsl:function name="am:concatSQLStrings" as="xs:string">&lt;xsl:param name="var.strings" as="xs:string*"/>&lt;xsl:choose>&lt;xsl:when test="count($var.strings)  = 0">&lt;xsl:value-of select="am:stringToDB('')"/>&lt;/xsl:when>&lt;xsl:when test="count($var.strings) = 1">&lt;xsl:value-of select="$var.strings[1]"/>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:value-of select="concat('concat(', $var.strings[1], ' , ', am:concatSQLStrings($var.strings[position()&amp;gt; 1]), ')')"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="concat($var.strings[1], ' || ', am:concatSQLStrings($var.strings[position() &amp;gt; 1]))"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:function>&lt;!--2022-->&lt;xsl:function name="am:response" as="element()">&lt;xsl:param name="var.body" as="element()"/>&lt;xsl:param name="var.log" as="element()?"/>&lt;response>&lt;result>true&lt;/result>&lt;overallResult>true&lt;/overallResult>&lt;responses>&lt;response>

      &lt;result>true&lt;/result>&lt;xsl:copy-of select="$var.session/response/*"/>&lt;body>&lt;xsl:copy-of select="$var.session/body/*"/>&lt;xsl:copy-of select="$var.body/*"/>&lt;/body>



    &lt;/response>&lt;/responses>&lt;log>&lt;entries>&lt;xsl:for-each select="$var.log/entries/*">&lt;xsl:copy>&lt;xsl:copy-of select="$var.session/response/requestId"/>&lt;xsl:copy-of select="*"/>&lt;/xsl:copy>&lt;/xsl:for-each>&lt;/entries>&lt;/log>&lt;/response>&lt;/xsl:function>&lt;!--Datei 2-->&lt;xsl:function name="am:templateAttribute" as="element()?">
    &lt;xsl:param name="attribute" as="element()?"/>
     &lt;xsl:if test="exists($attribute)">&lt;xsl:element name="{ name($attribute) }">&lt;xsl:copy-of select="$attribute/*[not(self::key | self::type | self::displayName | self::displayDescription | self::displayEmptyText | self::enums | self::attribute | self::attributes)]"/>&lt;xsl:if test="$attribute/key != ''">
               &lt;key>
                 &lt;xsl:value-of select="$attribute/key"/>
               &lt;/key>
          &lt;/xsl:if>&lt;type>&lt;xsl:value-of select="if ($attribute/type != '') then $attribute/type else 'string'"/>&lt;/type>&lt;xsl:sequence select="am:displayNameTranslation($var.session, $attribute/labels, $attribute/key)">

          &lt;/xsl:sequence>&lt;xsl:sequence select="am:maybeDisplayDescriptionTranslation($var.session, $attribute/descriptions)">

          &lt;/xsl:sequence>&lt;xsl:variable name="emptyText" select="am:translation($var.session, $attribute/emptyTexts)">

          &lt;/xsl:variable>&lt;xsl:if test="$emptyText != ''">&lt;displayEmptyText>&lt;xsl:value-of select="$emptyText"/>&lt;/displayEmptyText>&lt;/xsl:if>&lt;xsl:choose>&lt;xsl:when test="$attribute/type = 'boolean' and not(exists($attribute/defaultValue))">
               &lt;defaultValue>false&lt;/defaultValue>
          &lt;/xsl:when>&lt;xsl:when test="$attribute/type = 'enum' or $attribute/type = 'staticEnum'">
               &lt;enums>
                 &lt;xsl:for-each select="$attribute/enums/enum">
                    &lt;enum>
                      &lt;key>
                         &lt;xsl:value-of select="key"/>
                      &lt;/key>
                      &lt;xsl:sequence select="am:displayNameTranslation($var.session, labels, key)"/>&lt;xsl:copy-of select="colorCode | labels | enabledForValues"/>

                    &lt;/enum>
                 &lt;/xsl:for-each>
               &lt;/enums>
          &lt;/xsl:when>&lt;xsl:when test="$attribute/type = 'list'">&lt;attribute>&lt;xsl:sequence select="am:templateAttribute($attribute/attribute)/*"/>&lt;/attribute>

          &lt;/xsl:when>&lt;xsl:when test="$attribute/type = 'group' or $attribute/type = 'table'">
               &lt;attributes>
                 &lt;xsl:for-each select="$attribute/attributes/attribute">&lt;xsl:sequence select="am:templateAttribute(.)"/>

                 &lt;/xsl:for-each>
               &lt;/attributes>
          &lt;/xsl:when>&lt;/xsl:choose>&lt;/xsl:element>&lt;/xsl:if>

  &lt;/xsl:function>&lt;xsl:function name="am:nonHiddenAttribute" as="element()?">
    &lt;xsl:param name="attribute" as="element()"/>
     &lt;xsl:if test="not($attribute/hidden = 'true')">&lt;attribute>&lt;xsl:copy-of select="$attribute/*[not(self::attributes)]"/>&lt;xsl:if test="exists($attribute/attributes)">
               &lt;attributes>
                 &lt;xsl:for-each select="$attribute/attributes/attribute">&lt;xsl:sequence select="am:nonHiddenAttribute(.)"/>

                 &lt;/xsl:for-each>
               &lt;/attributes>
          &lt;/xsl:if>&lt;/attribute>&lt;/xsl:if>

  &lt;/xsl:function>&lt;xsl:function name="am:languageTranslation">&lt;xsl:param name="var.language"/>&lt;xsl:param name="var.translations" as="element()?"/>&lt;xsl:param name="var.default"/>&lt;xsl:choose>
                 &lt;xsl:when test="exists($var.translations/*[local-name() = $var.language]/text())">
                    &lt;xsl:value-of select="$var.translations/*[local-name() = $var.language]/text()"/>
                 &lt;/xsl:when>

                 &lt;xsl:when test="exists($var.translations/en/text())">
                    &lt;xsl:value-of select="$var.translations/en/text()"/>
                 &lt;/xsl:when>&lt;xsl:when test="exists($var.translations/de/text())">
                    &lt;xsl:value-of select="$var.translations/de/text()"/>
                 &lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="$var.default"/>&lt;/xsl:otherwise>

               &lt;/xsl:choose>&lt;/xsl:function>&lt;xsl:function name="am:translation">&lt;xsl:param name="var.session" as="element()"/>&lt;xsl:param name="var.translations" as="element()?"/>&lt;xsl:sequence select="am:translation($var.session, $var.translations, '')"/>&lt;/xsl:function>&lt;xsl:function name="am:translation">&lt;xsl:param name="var.session" as="element()"/>&lt;xsl:param name="var.translations" as="element()?"/>&lt;xsl:param name="var.default"/>&lt;xsl:choose>
                 &lt;xsl:when test="exists($var.translations/*[local-name() = $var.session/user/locale/text()]/text())">
                    &lt;xsl:value-of select="$var.translations/*[local-name() = $var.session/user/locale/text()]/text()"/>
                 &lt;/xsl:when>
                 &lt;xsl:when test="exists($var.translations/*[local-name() = $var.session/user/language/text()]/text())">
                    &lt;xsl:value-of select="$var.translations/*[local-name() = $var.session/user/language/text()]/text()"/>
                 &lt;/xsl:when>
                 &lt;xsl:when test="exists($var.translations/en/text())">
                    &lt;xsl:value-of select="$var.translations/en/text()"/>
                 &lt;/xsl:when>&lt;xsl:when test="exists($var.translations/de/text())">
                    &lt;xsl:value-of select="$var.translations/de/text()"/>
                 &lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="$var.default"/>&lt;/xsl:otherwise>

               &lt;/xsl:choose>&lt;/xsl:function>&lt;xsl:function name="am:displayNameTranslation" as="element()">&lt;xsl:param name="var.session" as="element()"/>&lt;xsl:param name="var.translations" as="element()?"/>&lt;xsl:param name="var.default"/>&lt;displayName>&lt;xsl:value-of select="am:translation($var.session, $var.translations, $var.default)"/>&lt;/displayName>&lt;/xsl:function>&lt;xsl:function name="am:maybeDisplayDescriptionTranslation" as="element()?">&lt;xsl:param name="var.session" as="element()"/>&lt;xsl:param name="var.translations" as="element()?"/>&lt;xsl:variable name="var.displayDescription" select="am:translation($var.session, $var.translations, '')"/>&lt;xsl:if test="$var.displayDescription != ''">&lt;displayDescription>&lt;xsl:value-of select="$var.displayDescription"/>&lt;/displayDescription>&lt;/xsl:if>&lt;/xsl:function>&lt;!--Datei 3-->&lt;xsl:function name="am:whereOrganizationFilter">&lt;xsl:param name="var.session" as="element()"/>&lt;xsl:param name="var.tableName"/>&lt;xsl:value-of>&lt;xsl:text> where (&lt;/xsl:text>&lt;xsl:value-of select="$var.tableName"/>&lt;xsl:text>.organizationId = &lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB($var.session/user/organizations/organization/id)"/>&lt;xsl:text> and &lt;/xsl:text>&lt;xsl:value-of select="$var.tableName"/>&lt;xsl:text>.deleted = '0') &lt;/xsl:text>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:userNameFilters">&lt;xsl:param name="var.filters" as="element()?"/>&lt;xsl:value-of>&lt;xsl:for-each select="$var.filters/filter[key = 'createdByUserDisplayName']">&lt;xsl:choose>&lt;xsl:when test="starts-with(operator, 'contains')">&lt;xsl:variable name="var.filter" as="element()">&lt;filter>
        &lt;key>displayName&lt;/key>&lt;xsl:copy-of select="operator | value"/>


      &lt;/filter>&lt;/xsl:variable>&lt;xsl:value-of select="am:containsFilter($var.filter, 'cu')"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="am:plainFilter(., 'cu.displayName', 'string')"/>&lt;/xsl:otherwise>&lt;/xsl:choose>

&lt;/xsl:for-each>&lt;xsl:for-each select="$var.filters/filter[key = 'lastUpdatedByUserDisplayName']">&lt;xsl:choose>&lt;xsl:when test="starts-with(operator, 'contains')">&lt;xsl:variable name="var.filter" as="element()">&lt;filter>
        &lt;key>displayName&lt;/key>&lt;xsl:copy-of select="operator | value"/>


      &lt;/filter>&lt;/xsl:variable>&lt;xsl:value-of select="am:containsFilter($var.filter, 'luu')"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="am:plainFilter(., 'luu.displayName', 'string')"/>&lt;/xsl:otherwise>&lt;/xsl:choose>

&lt;/xsl:for-each>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:metaFilters">&lt;xsl:param name="var.filters" as="element()?"/>&lt;xsl:param name="var.tableName"/>&lt;xsl:value-of>&lt;xsl:for-each select="$var.filters/filter">
       &lt;xsl:choose>&lt;xsl:when test="key = 'id'">&lt;xsl:value-of select="am:plainFilter(., concat($var.tableName, '.id'), 'number')"/>&lt;/xsl:when>



          &lt;xsl:when test="key = 'createdOn'">&lt;xsl:value-of select="am:plainFilter(., concat($var.tableName, '.createdOn'), 'dateTime')"/>

          &lt;/xsl:when>
          &lt;xsl:when test="key = 'createdByUserId'">&lt;xsl:value-of select="am:plainFilter(., concat($var.tableName, '.createdByUserId'), 'string')"/>

          &lt;/xsl:when>
          &lt;xsl:when test="key = 'lastUpdatedOn'">
            &lt;xsl:value-of select="am:plainFilter(., concat($var.tableName, '.lastUpdatedOn'), 'dateTime')"/>
          &lt;/xsl:when>
          &lt;xsl:when test="key = 'lastUpdatedByUserId'">
            &lt;xsl:value-of select="am:plainFilter(., concat($var.tableName, '.lastUpdatedByByUserId'), 'string')"/>
          &lt;/xsl:when>
       &lt;/xsl:choose>
     &lt;/xsl:for-each>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:plainFilter">&lt;xsl:param name="var.inputFilter" as="element()"/>&lt;xsl:param name="var.column"/>&lt;xsl:param name="var.type"/>&lt;xsl:variable name="var.isOracleString" select="$var.type = 'string' and $databaseType = 'oracle'" as="xs:boolean">&lt;!--Oracle -> es gibt '' nicht, nur ggfs. auf NULL prüfen-->&lt;/xsl:variable>&lt;xsl:variable name="var.saneFilter" as="element()">&lt;filter>&lt;xsl:choose>&lt;xsl:when test="not($var.inputFilter/operator = ('=', '!=', 'in', 'not in', '&amp;lt;', '&amp;gt;', '&amp;lt;=', '&amp;gt;='))">&lt;xsl:value-of select="error(xs:QName('error'), concat('Invalid operator &amp;quot;', $var.inputFilter/operator, '&amp;quot;'))"/>&lt;/xsl:when>&lt;xsl:when test="$var.inputFilter/operator = ('in', 'not in')">&lt;operator>&lt;xsl:value-of select="$var.inputFilter/operator"/>&lt;/operator>&lt;values>&lt;xsl:for-each select="distinct-values($var.inputFilter/values/value)">&lt;value>&lt;xsl:value-of select="."/>&lt;/value>&lt;/xsl:for-each>&lt;/values>&lt;/xsl:when>&lt;xsl:otherwise>&lt;operator>&lt;xsl:value-of select="$var.inputFilter/operator"/>&lt;/operator>&lt;value>&lt;xsl:value-of select="$var.inputFilter/value"/>&lt;/value>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/filter>&lt;/xsl:variable>&lt;xsl:variable name="var.isNegative" as="xs:boolean" select="am:isNegativeFilter($var.saneFilter)"/>&lt;xsl:variable name="var.hasNull" as="xs:boolean">&lt;xsl:choose>&lt;xsl:when test="$var.saneFilter/operator = ('in', 'not in')">&lt;xsl:value-of select="exists($var.saneFilter/values/value[not(. != '')])"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:variable select="not($var.inputFilter/value != '')" name="var.hasNull" as="xs:boolean"/>&lt;xsl:if test="$var.hasNull and not($var.inputFilter/operator = ('=', '!='))">&lt;xsl:value-of select="error(xs:QName('error'), concat('Invalid operator &amp;quot;', $var.inputFilter/operator, '&amp;quot;', &amp;quot; for 'empty' query&amp;quot;))"/>&lt;/xsl:if>&lt;xsl:value-of select="$var.hasNull"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:variable>&lt;xsl:variable name="var.finalFilter" as="element()?">&lt;!--immer positiv, 'not' wird außen herumgeschrieben-->&lt;xsl:choose>&lt;xsl:when test="$var.saneFilter/operator = ('in', 'not in')">&lt;xsl:variable name="var.values" as="xs:string*" select="distinct-values($var.saneFilter/values/value[. != '' or not($var.isOracleString)])"/>&lt;xsl:choose>&lt;xsl:when test="count($var.values) = 0">&lt;filter>&lt;operator>&lt;xsl:value-of select="'false'"/>&lt;/operator>&lt;/filter>&lt;/xsl:when>&lt;xsl:when test="count($var.values) = 1">&lt;filter>&lt;operator>&lt;xsl:value-of select="'='"/>&lt;/operator>&lt;value>&lt;xsl:value-of select="$var.values"/>&lt;/value>&lt;/filter>&lt;/xsl:when>&lt;xsl:otherwise>&lt;filter>&lt;operator>&lt;xsl:value-of select="'='"/>&lt;!--keine Unterschiede mehr zwischen '=' und 'in' hier-->&lt;/operator>&lt;values>&lt;xsl:for-each select="$var.values">&lt;value>&lt;xsl:value-of select="."/>&lt;/value>&lt;/xsl:for-each>&lt;/values>&lt;/filter>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:when>&lt;xsl:when test="$var.saneFilter/value != '' or not($var.isOracleString)">&lt;xsl:sequence select="am:positiveFilter($var.saneFilter)"/>&lt;/xsl:when>&lt;/xsl:choose>&lt;/xsl:variable>&lt;xsl:value-of>&lt;xsl:if test="$var.hasNull or exists($var.finalFilter)">&lt;xsl:text> and (&lt;/xsl:text>&lt;xsl:if test="$var.isNegative">&lt;xsl:if test="not($var.hasNull)">&lt;xsl:value-of select="$var.column"/>&lt;xsl:text> is null or &lt;/xsl:text>&lt;/xsl:if>&lt;xsl:text>not &lt;/xsl:text>&lt;/xsl:if>&lt;xsl:text> (&lt;/xsl:text>&lt;xsl:if test="$var.hasNull">&lt;xsl:value-of select="$var.column"/>&lt;xsl:text> is null &lt;/xsl:text>&lt;xsl:if test="exists($var.finalFilter)">&lt;xsl:text> or &lt;/xsl:text>&lt;/xsl:if>&lt;/xsl:if>&lt;xsl:choose>&lt;xsl:when test="not(exists($var.finalFilter))"/>&lt;xsl:when test="$var.finalFilter/operator = 'true'"> 1 = 1 &lt;/xsl:when>&lt;xsl:when test="$var.finalFilter/operator = 'false'"> 0 = 1 &lt;/xsl:when>&lt;xsl:when test="exists($var.finalFilter/values)">&lt;xsl:text> ( &lt;/xsl:text>          &lt;xsl:value-of select="$var.column"/>&lt;xsl:text> in (&lt;/xsl:text>&lt;xsl:for-each select="$var.finalFilter/values/value">&lt;xsl:choose>&lt;xsl:when test="position() mod 1000 = 0">&lt;xsl:value-of select="concat(') or ', $var.column, ' in (')"/>&lt;/xsl:when>&lt;xsl:when test="position() &amp;gt; 1">, &lt;/xsl:when>&lt;/xsl:choose>&lt;xsl:value-of select="am:printValue($var.type, .)"/>&lt;/xsl:for-each>&lt;xsl:text>))&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="$var.column"/>&lt;xsl:choose>&lt;xsl:when test="$var.finalFilter/operator = ('=', '&amp;lt;', '&amp;gt;', '&amp;lt;=', '&amp;gt;=')">&lt;xsl:text> &lt;/xsl:text>&lt;xsl:value-of select="$var.finalFilter/operator"/>&lt;xsl:text> &lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="error(xs:QName('error'), concat('Invalid operator &amp;quot;', $var.finalFilter/operator, '&amp;quot;'))"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;xsl:value-of select="am:printValue($var.type, $var.finalFilter/value)"/>
&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:if>&lt;xsl:text>) )&lt;/xsl:text>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:containsFilter">&lt;xsl:param name="filter" as="element()"/>&lt;xsl:param name="table"/>&lt;xsl:value-of>&lt;xsl:text> and (&lt;/xsl:text>&lt;xsl:choose>&lt;xsl:when test="$filter/operator = 'contains' and not($filter/value != '')">&lt;xsl:text> 1 = 1&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:when test="$filter/operator = 'contains not' and not($filter/value != '')">&lt;xsl:text> 0 = 1&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:if test="$filter/operator = 'contains not'">&lt;xsl:text> not &lt;/xsl:text>&lt;/xsl:if>&lt;xsl:text> (contains((&lt;/xsl:text>&lt;xsl:value-of select="concat($table, &amp;quot;.&amp;quot;, am:escapeString($filter/key))"/>&lt;xsl:text> ), '&lt;/xsl:text>&lt;xsl:value-of select="concat('&amp;quot;*', am:escapeString($filter/value), '*&amp;quot;')"/>&lt;xsl:text>'))&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:if test="$filter/operator = 'contains not'">&lt;xsl:text> not (&lt;/xsl:text>&lt;/xsl:if>&lt;xsl:text> to_tsvector('vamsearch',&lt;/xsl:text>&lt;xsl:value-of select="concat($table, &amp;quot;.&amp;quot;, am:escapeString($filter/key))"/>&lt;xsl:text> ) @@ to_tsquery('vamsearch',&lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB(concat(&amp;quot;'&amp;quot;, replace($filter/value, '[^\p{L}\p{M}]', ' '), &amp;quot;':*&amp;quot;))"/>&lt;xsl:text>)&lt;/xsl:text>&lt;xsl:if test="$filter/operator = 'contains not'">&lt;xsl:text>)&lt;/xsl:text>&lt;/xsl:if>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:variable name="var.key" select="if (contains($filter/key, '.')) then substring-after($filter/key, '.') else $filter/key"/>&lt;xsl:if test="$filter/operator = 'contains not'">&lt;xsl:value-of select="concat($table, '.', am:escapeString($var.key), ' IS NULL OR NOT ')"/>&lt;/xsl:if>&lt;xsl:text>(

(&lt;/xsl:text>&lt;!--VAM-288: Prüfung auf exakt gleich-->&lt;xsl:value-of select="concat($table, '.', am:escapeString($var.key), ' = ', am:stringToDB($filter/value))"/>&lt;xsl:text>)
or
contains(&lt;/xsl:text>&lt;xsl:value-of select="$table"/>&lt;xsl:text>.ctxDummy, '
          &lt;/xsl:text>&lt;xsl:text>(%&lt;/xsl:text>&lt;xsl:value-of select="am:escapeContainsString($filter/value)"/>&lt;xsl:text>% within (&lt;/xsl:text>&lt;xsl:value-of select="am:escapeString($var.key)"/>&lt;xsl:text>))
          &lt;/xsl:text>&lt;xsl:text>
        ') &amp;gt; 0
)&lt;/xsl:text>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;xsl:text>) &lt;/xsl:text>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:isNegativeFilter" as="xs:boolean">&lt;xsl:param name="var.filter" as="element()"/>&lt;xsl:sequence select="$var.filter/operator = ('not in', '!=')"/>&lt;/xsl:function>&lt;xsl:function name="am:positiveFilter" as="element()">&lt;xsl:param name="var.filter" as="element()"/>&lt;xsl:for-each select="$var.filter">&lt;xsl:copy>&lt;xsl:copy-of select="*[not(self::operator)]"/>&lt;operator>&lt;xsl:choose>&lt;xsl:when test="operator = 'not in'">in&lt;/xsl:when>&lt;xsl:when test="operator = '!='">=&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="operator"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/operator>&lt;/xsl:copy>&lt;/xsl:for-each>&lt;/xsl:function>&lt;xsl:function name="am:printValue">
    &lt;xsl:param name="type"/>
    &lt;xsl:param name="value"/>&lt;xsl:value-of>&lt;xsl:choose>
      &lt;xsl:when test="$type = 'boolean'">
        &lt;xsl:choose>
          &lt;xsl:when test="xs:string($value) = ('true', '1')">&lt;xsl:text>'1'&lt;/xsl:text>&lt;/xsl:when>
          &lt;xsl:otherwise>&lt;xsl:text>'0'&lt;/xsl:text>&lt;/xsl:otherwise>
        &lt;/xsl:choose>
      &lt;/xsl:when>
      &lt;xsl:when test="$type = 'dateTime'">
        &lt;xsl:value-of select="am:timestampToDB($value)"/>
      &lt;/xsl:when>
      &lt;xsl:when test="$type = 'number'">
        &lt;xsl:value-of select="am:numberToDB($value)"/>
      &lt;/xsl:when>
      &lt;xsl:otherwise>&lt;!-- $type = 'enum' or $type = 'string' -->
        &lt;xsl:text>'&lt;/xsl:text>&lt;xsl:value-of select="am:escapeString($value)"/>&lt;xsl:text>'&lt;/xsl:text>
      &lt;/xsl:otherwise>
    &lt;/xsl:choose>&lt;/xsl:value-of>


  &lt;/xsl:function>&lt;xsl:function name="am:templateDisplayName">&lt;xsl:param name="session" as="element()"/>&lt;xsl:param name="var.column"/>&lt;xsl:value-of>&lt;xsl:text>(&lt;/xsl:text>&lt;xsl:if test="$databaseType = 'mssql'">&lt;xsl:value-of select="'dbo.'"/>&lt;/xsl:if>&lt;xsl:text>getTemplateDisplayName(&lt;/xsl:text>&lt;xsl:value-of select="$var.column, am:comma()"/>&lt;xsl:value-of select="am:stringToDB($var.session/user/locale), am:comma(), am:stringToDB($var.session/user/language)"/>&lt;xsl:text>))&lt;/xsl:text>&lt;/xsl:value-of>









  &lt;/xsl:function>&lt;xsl:function name="am:orderBy">&lt;xsl:param name="sorter" as="element()"/>&lt;xsl:param name="column"/>&lt;xsl:value-of select="concat($column, am:sortDirection($sorter))"/>&lt;/xsl:function>&lt;xsl:function name="am:orderByWithNull">&lt;xsl:param name="sorter" as="element()"/>&lt;xsl:param name="column"/>&lt;xsl:value-of select="concat($column, am:sortDirectionWithNull($sorter))"/>&lt;/xsl:function>&lt;xsl:function name="am:sortDirection">&lt;xsl:param name="sorter" as="element()"/>&lt;xsl:choose>
      &lt;xsl:when test="$sorter/direction = 'desc'"> desc,&lt;/xsl:when>
      &lt;xsl:otherwise> asc,&lt;/xsl:otherwise>
    &lt;/xsl:choose>&lt;/xsl:function>&lt;xsl:function name="am:sortDirectionWithNull">&lt;!--Variante wo der Wert NULL sein könnte, aber deterministisch (an den Anfang) sortiert werden soll (VAM-1220)-->&lt;xsl:param name="sorter" as="element()"/>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:sequence select="am:sortDirection($sorter)">&lt;!--nicht unterstützt von MSSQL, aber automatisch richtig-->&lt;/xsl:sequence>&lt;/xsl:when>
      &lt;xsl:when test="$sorter/direction = 'desc'"> desc nulls last,&lt;/xsl:when>
      &lt;xsl:otherwise> asc nulls first,&lt;/xsl:otherwise>
    &lt;/xsl:choose>&lt;/xsl:function>&lt;xsl:function name="am:paging">&lt;xsl:param name="var.start"/>&lt;xsl:param name="var.limit"/>&lt;xsl:param name="var.tableName"/>&lt;xsl:value-of>&lt;xsl:if test="$var.start != '' and $var.limit != ''">&lt;xsl:text>where &lt;/xsl:text>&lt;xsl:value-of select="$var.tableName"/>&lt;xsl:text>.rownumber &amp;gt;= &lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.start + 1)"/>&lt;xsl:text> and &lt;/xsl:text>&lt;xsl:value-of select="$var.tableName"/>&lt;xsl:text>.rownumber &amp;lt;= &lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.start + $var.limit)"/>&lt;/xsl:if>&lt;xsl:text> order by &lt;/xsl:text>&lt;xsl:value-of select="$var.tableName"/>&lt;xsl:text>.rownumber&lt;/xsl:text>&lt;/xsl:value-of>&lt;/xsl:function>&lt;!--Datei 4-->&lt;xsl:function name="am:attributesToPersistentForm">&lt;!--TODO: diese Funktion soll auch für Oracle verwendet werden und die 'xmlelement'-Struktur dann daraus-->
    &lt;xsl:param name="asset"/>
    &lt;xsl:param name="assetAttributes"/>
    &lt;xsl:param name="templateAttributes"/>&lt;attributes>&lt;xsl:for-each select="$templateAttributes/attribute">
        &lt;xsl:variable name="key" select="key"/>&lt;xsl:variable name="assetAttribute" select="$assetAttributes/attribute[key=$key]" as="element()?"/>&lt;attribute>&lt;key>&lt;xsl:value-of select="$key"/>&lt;/key>&lt;xsl:choose>&lt;xsl:when test="type = 'group'">&lt;xsl:sequence select="am:attributesToPersistentForm($asset, $assetAttribute/attributes, attributes)"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;value>&lt;xsl:copy-of select="if (exists($assetAttribute/value)) then $assetAttribute/value/node() else defaultValue/node()"/>&lt;/value>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/attribute>&lt;/xsl:for-each>&lt;/attributes>&lt;/xsl:function>&lt;xsl:function name="am:attributesToPersistentForm2">&lt;xsl:param name="template"/>

    &lt;xsl:param name="assetAttributes"/>
    &lt;xsl:param name="templateAttributes"/>&lt;xsl:element name="{ concat('t', $template/id) }">&lt;xsl:sequence select="am:attributesToPersistentFormSub($template, $assetAttributes, $templateAttributes)"/>&lt;/xsl:element>&lt;/xsl:function>&lt;xsl:function name="am:attributesToPersistentFormSub">&lt;xsl:param name="template"/>

    &lt;xsl:param name="assetAttributes"/>
    &lt;xsl:param name="templateAttributes"/>&lt;xsl:for-each select="$templateAttributes/attribute">
        &lt;xsl:variable name="key" select="key"/>&lt;xsl:variable name="assetAttribute" select="$assetAttributes/attribute[key=$key]" as="element()?"/>&lt;xsl:element name="{ am:attributeKeyToQName($key) }">&lt;xsl:choose>&lt;xsl:when test="type = 'group'">&lt;xsl:sequence select="am:attributesToPersistentFormSub($template, $assetAttribute/attributes, attributes)"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:copy-of select="if (exists($assetAttribute/value)) then $assetAttribute/value/node() else defaultValue/node()"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:element>&lt;/xsl:for-each>&lt;/xsl:function>&lt;xsl:function name="am:attributesToPersistentForm3">&lt;xsl:param name="template"/>

    &lt;xsl:param name="assetAttributes"/>
    &lt;xsl:param name="templateAttributes"/>&lt;xsl:variable name="var.attributes" as="element()">&lt;attributes>&lt;xsl:sequence select="am:attributesToPersistentForm3Sub($template, $assetAttributes, $templateAttributes)"/>&lt;/attributes>&lt;/xsl:variable>&lt;xsl:value-of select="json:tuple($var.attributes)"/>&lt;/xsl:function>&lt;xsl:function name="am:attributesToPersistentForm3Sub">&lt;xsl:param name="template"/>

    &lt;xsl:param name="assetAttributes"/>
    &lt;xsl:param name="templateAttributes"/>&lt;xsl:for-each select="$templateAttributes/attribute">
        &lt;xsl:variable name="key" select="key"/>&lt;xsl:variable name="assetAttribute" select="$assetAttributes/attribute[key=$key]" as="element()?"/>&lt;xsl:element name="{ am:attributeKeyToQName($key) }">&lt;xsl:choose>&lt;xsl:when test="type = 'group'">&lt;xsl:attribute name="type" select="'tuple'"/>&lt;xsl:sequence select="am:attributesToPersistentForm3Sub($template, $assetAttribute/attributes, attributes)"/>&lt;/xsl:when>&lt;xsl:when test="type = 'table'">&lt;xsl:attribute name="type" select="'relation'"/>&lt;xsl:sequence select="$assetAttribute/value/rows/row"/>&lt;/xsl:when>&lt;xsl:when test="type = 'list'">&lt;xsl:attribute name="type" select="'array'"/&gt;&lt;xsl:sequence select="$assetAttribute/value/items/item"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:copy-of select="if (exists($assetAttribute/value)) then $assetAttribute/value/node() else defaultValue/node()"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:element>&lt;/xsl:for-each>&lt;/xsl:function>&lt;xsl:function name="am:attributesToElementForm" as="element()*">&lt;xsl:param name="var.attributes" as="element()"/>&lt;xsl:for-each select="$var.attributes/*">&lt;xsl:element name="{ key }">&lt;xsl:choose>&lt;xsl:when test="exists(value/items)">&lt;xsl:copy-of select="value/items/item"/>&lt;/xsl:when>&lt;xsl:when test="exists(value/rows)">&lt;xsl:copy-of select="value/rows/row"/>&lt;/xsl:when>&lt;xsl:when test="exists(attributes)">&lt;xsl:copy-of select="am:attributesToElementForm(attributes)"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:copy-of select="value/node()"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:element>&lt;/xsl:for-each>&lt;/xsl:function>&lt;xsl:function name="am:childrenToPersistentForm" as="element()">
    &lt;xsl:param name="asset" as="element()"/>&lt;assets>&lt;xsl:for-each select="$asset/version/childTemplates/template/assets/asset">&lt;xsl:sort select="number(id)"/>&lt;asset>&lt;xsl:copy-of select="id | linkedFrom | linkedTo"/>&lt;/asset>&lt;/xsl:for-each>&lt;/assets>

    &lt;/xsl:function>&lt;xsl:function name="am:nolimitagg">&lt;!--listagg ohne Längenbeschränkung (siehe VAM-191)-->&lt;xsl:param name="var.field"/>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:value-of select="concat(&amp;quot;DISTINCT &amp;quot;, $var.field, &amp;quot; + '; ' FROM ASSETS AS acc     INNER JOIN ASS_CHILDREN AS s     ON s.CHILDASSETID = acc.ID&amp;quot;)"/>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:value-of select="error(xs:QName('error'), 'not used')"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="concat(&amp;quot; rtrim(dbms_xmlgen.convert(xmlagg(xmlelement(e, &amp;quot;, $var.field, &amp;quot;, ', ').extract('//text()') order by &amp;quot;,  $var.field, &amp;quot;).GetClobVal(), 1), ', ') joinedDisplayNames &amp;quot;)"/>&lt;!--Umweg über XML-Funktionen-->&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:function>&lt;xsl:function name="am:checkDuplicateCustomId">&lt;xsl:param name="var.templateId"/>&lt;xsl:param name="var.newCustomId"/>&lt;xsl:param name="var.assetId"/>&lt;query properties="force" queryID="checkCustomId">&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;value>&lt;xsl:text>IF 0 &amp;lt; (SELECT count(*) FROM assets WHERE customId = &lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB($var.newCustomId)"/>&lt;xsl:if test="$var.assetId != ''">&lt;xsl:text> and id != &lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.assetId)"/>&lt;/xsl:if>&lt;xsl:text> and templateId = &lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.templateId)"/>&lt;xsl:text> and deleted = '0') THROW 50201, 'Duplicate customId', 1&lt;/xsl:text>&lt;/value>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;value>&lt;xsl:text>select checkCustomIdDuplicate(&lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB($var.session/user/organizations/organization/id), am:comma()"/>&lt;xsl:value-of select="am:numberToDB($var.templateId), am:comma()"/>&lt;xsl:value-of select="am:stringToDB($var.newCustomId), am:comma()"/>&lt;xsl:value-of select="am:numberToDB(if($var.assetId != '') then $var.assetId else -1)"/>&lt;xsl:text>)&lt;/xsl:text>&lt;/value>&lt;/xsl:when>&lt;xsl:otherwise>&lt;value>&lt;xsl:text>begin
declare v_count number(8, 0);
begin
select count(*) into v_count from assets where customId =
&lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB($var.newCustomId)"/>&lt;xsl:if test="$var.assetId != ''">&lt;xsl:text> and id != &lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.assetId)"/>&lt;/xsl:if>&lt;xsl:text> and templateId = &lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.templateId)"/>&lt;xsl:text> and deleted = '0';
if (v_count &amp;gt; 0) then
raise_application_error(-20000, 'Duplicate customId');
end if;
end;
end;&lt;/xsl:text>
    &lt;/value>&lt;/xsl:otherwise>&lt;/xsl:choose>


      &lt;/query>&lt;/xsl:function>&lt;xsl:function name="am:mssqlAgg">&lt;xsl:param name="var.field"/>&lt;xsl:param name="var.source"/>&lt;xsl:variable name="var.string" select="', '"/>&lt;xsl:value-of>&lt;xsl:text>(
select case when LEN(s) &amp;gt; 1024 then CONCAT(SUBSTRING(s, 1, 1021), '...') ELSE s END from&lt;/xsl:text>&lt;xsl:text>(SELECT COALESCE(STUFF((SELECT &lt;/xsl:text>&lt;xsl:value-of select="am:stringToDB($var.string)"/>&lt;xsl:text> + &lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text> &lt;/xsl:text>&lt;xsl:value-of select="$var.source"/>&lt;xsl:text> ORDER BY &lt;/xsl:text>&lt;xsl:value-of select="$var.field"/>&lt;xsl:text>          FOR XML PATH(''), TYPE             ).value('.', 'NVARCHAR(MAX)')         ,1, &lt;/xsl:text>&lt;xsl:value-of select="string-length($var.string)"/>&lt;xsl:text>,''), '') 
          s) dummyTable&lt;/xsl:text>&lt;xsl:text>)  &lt;/xsl:text>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:explicitChildrenDisplayNames" as="xs:string">&lt;xsl:param name="var.childAssets" as="element()*"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:value-of select="am:mssqlAgg('acc.displayName', concat('FROM ASSETS AS acc WHERE ', am:keyInAssetList('acc.id', $var.childAssets)))"/>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:text>(
select case when (length(s) &amp;gt; 1024) then concat(substring(s, 1, 1021), '...') else s end from
(
select
string_agg(displayName, ', ' order by displayName) s from (select acc.displayName from ASSETS as acc where
&lt;/xsl:text>&lt;xsl:value-of select="am:keyInAssetList('acc.id', $var.childAssets)"/>&lt;xsl:text>) dummy
) dummy )
&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:text>(
select case when length(rs.joinedDisplayNames) &amp;gt; 1024 then concat(substr(rs.joinedDisplayNames, 1, 1021), '...') else (rs.joinedDisplayNames) end from
(
select
&lt;/xsl:text>&lt;xsl:value-of select="am:nolimitagg('acc.displayName')"/>&lt;xsl:text> from assets acc
 where &lt;/xsl:text>&lt;xsl:value-of select="am:keyInAssetList('acc.id', $var.childAssets)"/>&lt;xsl:text>
) rs
)
  &lt;/xsl:text>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="am:childrenDisplayNames">&lt;xsl:param name="var.id"/>&lt;xsl:value-of>&lt;xsl:choose>&lt;xsl:when test="$databaseType = 'mssql'">&lt;xsl:value-of select="am:mssqlAgg('acc.displayName', concat('FROM ASSETS AS acc INNER JOIN ASS_CHILDREN AS c ON c.CHILDASSETID = acc.ID where c.ASSETID = ', am:numberToDB($var.id)))"/>&lt;/xsl:when>&lt;xsl:when test="$databaseType = 'postgresql'">&lt;xsl:text>(
select case when (length(s) &amp;gt; 1024) then concat(substring(s, 1, 1021), '...') else s end from
(
select
string_agg(displayName, ', ' order by displayName) s from (select acc.displayName from ASSETS as acc inner join ASS_CHILDREN as s on s.CHILDASSETID = acc.ID where assetId=
&lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.id)"/>&lt;xsl:text>) dummy
) dummy )
&lt;/xsl:text>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:text>(
select case when length(rs.joinedDisplayNames) &amp;gt; 1024 then concat(substr(rs.joinedDisplayNames, 1, 1021), '...') else (rs.joinedDisplayNames) end from
(
select
&lt;/xsl:text>&lt;xsl:value-of select="am:nolimitagg('aca.displayName')"/>&lt;xsl:text>  from ass_children ac
  join assets aca
  on aca.id = ac.childAssetId
where ac.assetId = &lt;/xsl:text>&lt;xsl:value-of select="am:numberToDB($var.id)"/>&lt;xsl:text>
) rs
)
  &lt;/xsl:text>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:value-of>&lt;/xsl:function>&lt;xsl:function name="json:value">&lt;xsl:param name="_" as="element()"/>&lt;xsl:for-each select="$_">&lt;xsl:choose>&lt;xsl:when test="@null = 'true'">null&lt;/xsl:when>&lt;xsl:when test="@type = 'relation'">&lt;xsl:value-of select="json:relation(.)"/>&lt;/xsl:when>&lt;xsl:when test="@type = 'tuple'">&lt;xsl:value-of select="json:tuple(.)"/>&lt;/xsl:when>&lt;xsl:when test="@type = 'array'">&lt;xsl:copy-of select="json:array(.)"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="json:atom(.)"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:for-each>&lt;/xsl:function>&lt;xsl:function name="json:relation">&lt;!--relation = wie array, aberr alle Children werden automatisch (auch ohne Attribut) als Tuple interpretiert-->&lt;xsl:param name="_" as="element()"/>[&lt;xsl:for-each select="$_/*">&lt;xsl:if test="position() != 1">,&lt;/xsl:if>&lt;xsl:value-of select="json:tuple(.)"/>&lt;/xsl:for-each>]&lt;/xsl:function>&lt;xsl:function name="json:array">&lt;xsl:param name="_" as="element()"/>[&lt;xsl:for-each select="$_/*">&lt;xsl:if test="position() != 1">,&lt;/xsl:if>&lt;xsl:value-of select="json:value(.)"/>&lt;/xsl:for-each>]&lt;/xsl:function>&lt;xsl:function name="json:tuple">&lt;xsl:param name="_" as="element()"/>{&lt;xsl:for-each select="$_/*">&lt;xsl:if test="position() != 1">,
&lt;/xsl:if>&lt;xsl:value-of select="json:string(name())"/>:&lt;xsl:value-of select="json:value(.)"/>&lt;/xsl:for-each>}&lt;/xsl:function>&lt;xsl:function name="json:atom">&lt;xsl:param name="_" as="element()"/>&lt;xsl:for-each select="$_">&lt;xsl:choose>&lt;xsl:when test="@type='boolean'">&lt;xsl:value-of select=".='true'"/>&lt;/xsl:when>&lt;xsl:otherwise>&lt;xsl:value-of select="json:string(.)"/>&lt;/xsl:otherwise>&lt;/xsl:choose>&lt;/xsl:for-each>&lt;/xsl:function>&lt;xsl:function name="json:string">&lt;xsl:param name="_"/>&lt;xsl:text>"&lt;/xsl:text>&lt;xsl:value-of select="replace(replace(replace(replace(replace($_, &amp;quot;\\&amp;quot;, &amp;quot;\\\\&amp;quot;),'&amp;quot;', '\\&amp;quot;'), &amp;quot;\r&amp;quot;, &amp;quot;\\r&amp;quot;), &amp;quot;\n&amp;quot;, &amp;quot;\\n&amp;quot;), &amp;quot;\t&amp;quot;, &amp;quot;\\t&amp;quot;)"/>&lt;xsl:text>"&lt;/xsl:text>&lt;/xsl:function>&lt;xsl:template match="/am:TEST">&lt;root>&lt;xsl:for-each select="filter">&lt;item>&lt;xsl:copy-of select="am:plainFilter(., 'abc', type)"/>&lt;/item>&lt;/xsl:for-each>&lt;/root>&lt;/xsl:template>
&lt;/xsl:stylesheet></Property>
	<Property name="xslt.target"></Property>
	<Property name="xslt.transformer">net.sf.saxon.TransformerFactoryImpl</Property>
</Properties>