<?xml version="1.0" encoding="UTF-8"?>
<?xmlspysamplexml E:\cio\projekte\basismodule\slinterface\res\resources\stylesheets\simpleVerReq.sl12.locref.xml?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sl12="http://www.buergerkarte.at/namespaces/securitylayer/20031231#" xmlns:sl11="http://www.buergerkarte.at/namespaces/securitylayer/20020831#" xmlns:sl10="http://www.buergerkarte.at/namespaces/securitylayer/20020225#" xmlns:moa="http://reference.e-government.gv.at/namespace/moa/20020822#">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  <xsl:variable name="trustProfileId">TrustProfile1</xsl:variable>
  <!-- ################################################################################################# -->
  <!-- # Templates -->
  <!-- ################################################################################################# -->
  <!-- =================================================================================================== -->
  <!-- Template für / -->
  <!-- =================================================================================================== -->
  <xsl:template match="/">
    <xsl:apply-templates select="*"/>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template für sl11:VerifyXMLSignatureRequest -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl11:VerifyXMLSignatureRequest">
    <moa:VerifyXMLSignatureRequest>
      <xsl:call-template name="copyNSDeclarations">
        <xsl:with-param name="sourceElem" select="sl11:VerifyXMLSignatureRequest"/>
      </xsl:call-template>
      <xsl:apply-templates select="sl11:DateTime"/>
      <xsl:apply-templates select="sl11:SignatureInfo"/>
      <xsl:apply-templates select="sl11:Supplement"/>
      <moa:ReturnHashInputData/>
      <moa:TrustProfileID>
        <xsl:copy-of select="$trustProfileId"/>
      </moa:TrustProfileID>
    </moa:VerifyXMLSignatureRequest>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template für sl12:VerifyXMLSignatureRequest -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl12:VerifyXMLSignatureRequest">
    <moa:VerifyXMLSignatureRequest>
      <xsl:call-template name="copyNSDeclarations">
        <xsl:with-param name="sourceElem" select="sl12:VerifyXMLSignatureRequest"/>
      </xsl:call-template>
      <xsl:apply-templates select="sl12:DateTime"/>
      <xsl:apply-templates select="sl12:SignatureInfo"/>
      <xsl:apply-templates select="sl12:Supplement"/>
      <moa:ReturnHashInputData/>
      <moa:Trustprofile>
        <xsl:copy-of select="$trustProfileId"/>
      </moa:Trustprofile>
    </moa:VerifyXMLSignatureRequest>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template für sl11:DateTime -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl11:DateTime">
    <moa:DateTime>
      <xsl:value-of select="."/>
    </moa:DateTime>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template für sl12:DateTime -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl12:DateTime">
    <moa:DateTime>
      <xsl:value-of select="."/>
    </moa:DateTime>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for sl11:SignatureInfo -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl11:SignatureInfo">
    <moa:VerifySignatureInfo>
      <moa:VerifySignatureEnvironment>
        <xsl:call-template name="content10">
          <xsl:with-param name="contentElem" select="sl11:SignatureEnvironment"/>
        </xsl:call-template>
      </moa:VerifySignatureEnvironment>
      <moa:VerifySignatureLocation xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
        <!-- Explicit namespace decl xmlns:dsig above is a workaround since damn Xalan does not correctly copy the namespace declarations -->
        <xsl:call-template name="copyNSDeclarations">
          <xsl:with-param name="sourceElem" select="./sl11:SignatureLocation"/>
        </xsl:call-template>
        <xsl:value-of select="sl11:SignatureLocation/node()"/>
      </moa:VerifySignatureLocation>
    </moa:VerifySignatureInfo>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for sl12:SignatureInfo -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl12:SignatureInfo">
    <moa:VerifySignatureInfo>
      <moa:VerifySignatureEnvironment>
        <xsl:call-template name="content12">
          <xsl:with-param name="contentElem" select="sl12:SignatureEnvironment"/>
        </xsl:call-template>
      </moa:VerifySignatureEnvironment>
      <moa:VerifySignatureLocation xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
        <!-- Explicit namespace decl xmlns:dsig above is a workaround since damn Xalan does not correctly copy the namespace declarations -->
        <xsl:call-template name="copyNSDeclarations">
          <xsl:with-param name="sourceElem" select="./sl12:SignatureLocation"/>
        </xsl:call-template>
        <xsl:value-of select="sl12:SignatureLocation/node()"/>
      </moa:VerifySignatureLocation>
    </moa:VerifySignatureInfo>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for sl11:Supplement -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl11:Supplement">
    <xsl:if test="sl10:MetaInfo">
      <moa:MetaInfo>
        <xsl:call-template name="metaInfo">
          <xsl:with-param name="metaInfoElem" select="sl10:MetaInfo"/>
        </xsl:call-template>
      </moa:MetaInfo>
    </xsl:if>
    <moa:Content>
      <xsl:call-template name="content10">
        <xsl:with-param name="contentElem" select="sl10:Content"/>
      </xsl:call-template>
    </moa:Content>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for sl12:Supplement -->
  <!-- =================================================================================================== -->
  <xsl:template match="sl12:Supplement">
    <xsl:if test="sl12:MetaInfo">
      <moa:MetaInfo>
        <xsl:call-template name="metaInfo">
          <xsl:with-param name="metaInfoElem" select="sl12:MetaInfo"/>
        </xsl:call-template>
      </moa:MetaInfo>
    </xsl:if>
    <moa:Content>
      <xsl:call-template name="content12">
        <xsl:with-param name="contentElem" select="sl12:Content"/>
      </xsl:call-template>
    </moa:Content>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for sl10:ContentOptionalRefType and sl10:ContentRequiredRefType -->
  <!-- =================================================================================================== -->
  <xsl:template name="content10">
    <xsl:param name="contentElem">default</xsl:param>
    <xsl:if test="$contentElem/@Reference">
      <xsl:attribute name="Reference"><xsl:value-of select="$contentElem/@Reference"/></xsl:attribute>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="$contentElem/sl10:Base64Content">
        <moa:Base64Content>
          <xsl:value-of select="$contentElem/sl10:Base64Content/node()"/>
        </moa:Base64Content>
      </xsl:when>
      <xsl:otherwise>
        <moa:XMLContent>
          <xsl:if test="$contentElem/sl10:XMLContent/@xml:space">
            <xsl:attribute name="xml:space"><xsl:value-of select="$contentElem/sl10:XMLContent/@xml:space"/></xsl:attribute>
          </xsl:if>
          <xsl:copy-of select="$contentElem/sl10:XMLContent/node()"/>
        </moa:XMLContent>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for sl12:ContentOptionalRefType and sl12:ContentRequiredRefType -->
  <!-- =================================================================================================== -->
  <xsl:template name="content12">
    <xsl:param name="contentElem">default</xsl:param>
    <xsl:if test="$contentElem/@Reference">
      <xsl:attribute name="Reference"><xsl:value-of select="$contentElem/@Reference"/></xsl:attribute>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="$contentElem/sl12:Base64Content">
        <moa:Base64Content>
          <xsl:value-of select="$contentElem/sl12:Base64Content/node()"/>
        </moa:Base64Content>
      </xsl:when>
      <xsl:when test="$contentElem/sl12:LocRefContent">
        <moa:LocRefContent>
          <xsl:value-of select="$contentElem/sl12:LocRefContent/node()"/>
        </moa:LocRefContent>
      </xsl:when>
      <xsl:otherwise>
        <moa:XMLContent>
          <xsl:if test="$contentElem/sl12:XMLContent/@xml:space">
            <xsl:attribute name="xml:space"><xsl:value-of select="$contentElem/sl12:XMLContent/@xml:space"/></xsl:attribute>
          </xsl:if>
          <xsl:copy-of select="$contentElem/sl12:XMLContent/node()"/>
        </moa:XMLContent>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for sl10:MetaInfoType -->
  <!-- =================================================================================================== -->
  <xsl:template name="metaInfo">
    <xsl:param name="metaInfoElem">default</xsl:param>
    <moa:MimeType>
      <xsl:value-of select="$metaInfoElem/sl10:MimeType/node()"/>
    </moa:MimeType>
    <xsl:if test="$metaInfoElem/sl10:Description">
      <moa:Description>
        <xsl:value-of select="$metaInfoElem/sl10:Description/node()"/>
      </moa:Description>
    </xsl:if>
    <xsl:if test="$metaInfoElem/*[not(self::sl10:MimeType or self::sl10:Description)]">
      <xsl:copy-of select="$metaInfoElem/*[not(self::sl10:MimeType or self::sl10:Description)]"/>
    </xsl:if>
  </xsl:template>
  <!-- =================================================================================================== -->
  <!-- Template for copying all namespace declarations of an element -->
  <!-- =================================================================================================== -->
  <xsl:template name="copyNSDeclarations">
    <xsl:param name="sourceElem">default</xsl:param>
    <xsl:for-each select="$sourceElem/namespace::*">
      <xsl:variable name="currentNodeName" select="name(.)"/>
      <xsl:variable name="currentNodeValue" select="string(.)"/>
      <xsl:attribute name="xmlns:{$currentNodeName}"><xsl:copy-of select="$currentNodeValue"></xsl:copy-of></xsl:attribute>
    </xsl:for-each>
  </xsl:template>  
</xsl:stylesheet>