<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="html"/>
   <xsl:template match="/">
      <html>
         <head>
            <style> img {margin:0; padding:0; vertical-align: middle; width:20px; height:20px} 
            td {padding-left:1mm; padding-right:1mm}
            </style>
            <title>Änderungsrecherche </title>
         </head>
         <body >
            <xsl:apply-templates select="metadocument/object"/>
         </body>
      </html>
   </xsl:template>
   <xsl:template match="metadocument/object">
      <!-- Header-Tabelle mit dem Änderungsstamm -->
      <table style="border-collapse:collapse; border:solid black 1; width=100%; font-family:sans-serif; font-size:8pt">
         <thead>
            <tr>
               <th style="border:solid black 1">
                  <xsl:text>Vorschlag</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Änd.Nr.</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Elementbeschreibung</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Status</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Projektname</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Ersteller</xsl:text>
               </th>
            </tr>
         </thead>
         <tbody/>
         <td style="border:solid black 1">
            <xsl:call-template name="object-icon">
               <xsl:with-param name="class" select="class"/>
            </xsl:call-template>
            <xsl:value-of select="attribute[@name='beGTAAenderungsArt']/value"/>
         </td>
         <td style="border:solid black 1">
            <xsl:value-of select="attribute[@name='ChangeProposalId']/value"/>
         </td>
         <td style="border:solid black 1">
            <xsl:value-of select="attribute[@name='ProposedChangeDesc']/value"/>
         </td>
         <td style="border:solid black 1">
            <xsl:value-of select="attribute[@name='LifeCycleState']/value"/>
         </td>
         <td style="border:solid black 1">
            <xsl:value-of select="attribute[@name='ProjectName']/value"/>
         </td>         
         <td style="border:solid black 1">
            <xsl:value-of select="attribute[@name='Creator']/value"/>
         </td>
      </table>
      <table
         style="border-collapse:collapse; font-size=10pt; border:solid black 1; width=100%; font-family:sans-serif; font-size:8pt"
         cellspacing="0">
         <thead>
            <tr>
               <th style="border:solid black 1">
                  <xsl:text>Name</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Elementbeschreibung</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Status</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Projektname</xsl:text>
               </th>
               <!--th style="border:solid black 1">
                  <xsl:text>Ersteller</xsl:text>
               </th -->
               <th style="border:solid black 1">
                  <xsl:text>Sichtenname</xsl:text>
               </th>
               <th style="border:solid black 1">
                  <xsl:text>Umbauart</xsl:text>
               </th>
            </tr>
         </thead>
         <tbody>
            <xsl:call-template name="tree-master">
               <xsl:with-param name="branch" select="relation"/>
               <xsl:with-param name="tree-structure-string"/>
            </xsl:call-template>
         </tbody>
      </table>
   </xsl:template>
   <xsl:template name="tree-master">
      <xsl:param name="branch"/>
      <xsl:param name="tree-structure-string"/>
      <!--
      Die Relationen zu Objekten hier werden optisch zusammengefaßt unter ihrem Relationsnamen. 
      Der Gruppenwechsel entscheidet also über die Baumstruktur.
      Wenn der Gruppenname sich zur vorigen Gruppe geändert hat, kommt der Relationsname mit 
      Beginnsymbol als Tabellenzeile in die Darstellung.
      Sonst gilt für alle Relationen gleichen Namens nur Verlängerung.
      Für jedes Objekt gilt dann in der baumstruktur entweder das gekippte T wenn es noch weitere 
      Relationen dieses Typs gibt, oder das Astendesymbol. Gleichermaßen wird für die nächste 
      Rekursionsebene entweder der strich oder das blank vorgehalten.
       -->  
      <xsl:for-each select="$branch">
           <!-- Wenn diese Relation die erste ihres Typs ist... -->
           <xsl:if  test="position() = 1 or @Relationship != preceding-sibling::relation[1]/@Relationship">
                   <tr>
                     <td colspan="10" style="margin:0; padding:0">
                        <xsl:copy-of select="$tree-structure-string"/>
                        <img src="./0111.png"
                        align="middle"
                        alt="New Relationship type begins"/>
                        <xsl:value-of select="class/prompt"/>
                     </td>
                  </tr>
            </xsl:if>
         
         <xsl:variable name="tree-structure-new-branch">
            <xsl:choose>
               <!-- Wenn diese Relation nicht die letzte ihres typs ist... -->
               <xsl:when test="position() != last() and @Relationship = following-sibling::relation[1]/@Relationship">
                  <img src="./1110.png" align="middle"
                     alt="More Relationship of this type to follow"/>
               </xsl:when>
               <xsl:otherwise>
                  <img src="./1100.png" align="middle"
                     alt="Last Relationship of this type"/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         <xsl:variable name="tree-structure-following">
            <xsl:choose>
               <!-- Wenn dieses Element nicht das letzte ist... -->
               <xsl:when test="@Relationship = following-sibling::relation/@Relationship">
                  <img
                     src="./1010.png" align="middle"
                     alt="Der Zweig geht nach einigen Blättern noch weiter"
                  />
               </xsl:when>
               <xsl:otherwise>
                  <img src="./0000.png"
                     align="middle" alt="Der Zweig ist schon zuende"/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         
         <!-- 
         Baumstruktur-Symbole sind jetzt festgelegt, jetzt Felder für Tabelle bestimmen.
         Einige Felder sind doppelt belegt - für unterschiedliche Objekttypen.
          -->
               <xsl:variable name="name">
                  <xsl:value-of select="object/attribute[@name='LDisplayedName']/value"/>
                  <xsl:value-of select="object/attribute[@name='PartNumber']/value"/>
                  <xsl:value-of select="object/attribute[@name='DocumentName']/value"/>
               </xsl:variable>
               <xsl:variable name="positionsnummer">
                  <xsl:call-template name="replace-null">
                     <xsl:with-param name="input"
                        select="object/attribute[@name='WorkOrderId']/value"/>
                  </xsl:call-template>
               </xsl:variable>
               <xsl:variable name="creator">
                  <xsl:call-template name="replace-null">
                     <xsl:with-param name="input">
                       <xsl:value-of select="object/attribute[@name='Creator']/value"/>
                       <xsl:value-of select="object/attribute[@name='Ersteller']/value"/>
                       </xsl:with-param>
                  </xsl:call-template>
               </xsl:variable>
               <xsl:variable name="beschreibung">
                  <xsl:call-template name="replace-null">
                     <xsl:with-param name="input">
                        <xsl:value-of
                           select="object/attribute[@name='beGTABeschreibPos']/value"/>
                        <xsl:value-of
                           select="object/attribute[@name='Benennung']/value"/>
                     </xsl:with-param>
                  </xsl:call-template>
               </xsl:variable>
               <xsl:variable name="status" select="object/attribute[@name='LifeCycleState']/value"/>
               <xsl:variable name="projekt" select="object/attribute[@name='ProjectName']/value"/>
               <xsl:variable name="sicht">
                  <xsl:call-template name="replace-null">
                     <xsl:with-param name="input">
                        <xsl:value-of
                           select="attribute[@name='ViewName']/value"/>
                     </xsl:with-param>
                  </xsl:call-template>
               </xsl:variable>
               <xsl:variable name="art">
                  <xsl:call-template name="replace-null">
                     <xsl:with-param name="input">
                        <xsl:value-of
                           select="attribute[@name='beGtaUmbauart']/value"/>
                     </xsl:with-param>
                  </xsl:call-template>
               </xsl:variable>
               <tr style="margin:0;padding:0">
                  <td style="margin:0; padding:0">
                     <xsl:copy-of select="$tree-structure-string"/>
                     <xsl:copy-of select="$tree-structure-new-branch"/>
                     <xsl:call-template name="object-icon">
                        <xsl:with-param name="class" select="class"/>
                     </xsl:call-template>
                     <xsl:value-of select="$name"/>
                     <xsl:value-of select="$positionsnummer"/>
                  </td>
                  <td nowrap="nowrap">
                     <xsl:value-of select="$beschreibung"/>
                  </td>
                  <td>
                     <xsl:value-of select="$status"/>
                  </td>
                  <td>
                     <xsl:value-of select="$projekt"/>
                  </td>
                  <!--td>
                     <xsl:value-of select="$creator"/>
                  </td-->
                  <td><xsl:value-of select="$sicht"/></td>
                  <td><xsl:value-of select="$art"/></td>
               </tr>
         <xsl:call-template name="tree-master">
            <xsl:with-param name="branch" select="./object/relation"/>
            <xsl:with-param name="tree-structure-string">
               <xsl:copy-of select="$tree-structure-string"/>
               <xsl:copy-of select="$tree-structure-following"/>
            </xsl:with-param>
         </xsl:call-template>
      </xsl:for-each>
   </xsl:template>
   <xsl:template name="object-icon">
      <xsl:param name="class"/>
      <xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
      <xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
      <xsl:variable name="src">
         <xsl:text>http://cec2.st.behr.de:7740/edmweb/edsplm/home/images/</xsl:text>
         <xsl:value-of select="translate($class/value,$ucletters,$lcletters)"/>
         <xsl:text>.sbm</xsl:text>
      </xsl:variable>
      <img src="{$src}" alt="{class/prompt}"
         align="middle" style="padding-right:1mm"/>
   </xsl:template>
   <xsl:template name="replace-null">
      <xsl:param name="input"/>
      <xsl:choose>
         <xsl:when test="$input='NULL'">
            <xsl:text>---</xsl:text>
         </xsl:when>
         <xsl:when test="$input!='NULL'">
            <xsl:value-of select="$input"/>
         </xsl:when>
      </xsl:choose>
   </xsl:template>
</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="xrtRpt01.xml" htmlbaseurl="" outputurl="" processortype="internal" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition><template match="/"><block path="html/body/xsl:apply&#x2D;templates" x="347" y="54"/></template><template match="metadocument/object"><block path="table/thead/th/xsl:value&#x2D;of" x="347" y="108"/><block path="table/thead/th[1]/xsl:value&#x2D;of" x="398" y="126"/><block path="table/thead/th[2]/xsl:value&#x2D;of" x="358" y="144"/><block path="table/thead/th[3]/xsl:value&#x2D;of" x="398" y="162"/><block path="table/thead/th[4]/xsl:value&#x2D;of" x="358" y="180"/></template></MapperBlockPosition></MapperMetaTag>
</metaInformation>
-->
