
<?xml version="1.0"?>

<!-- XSL:File for resolving dbxlinks by Dimitrio Malheiro in 2002 -->
<!-- This Version is made on the 18th of Juli 2002 -->
<!-- Version 1.2 Final... Recursiv transforming included -->
<!-- Warning: THIS SOFTWARE IS HIGH EXPERIMENTAL (first Alpha) -->
<!-- Aufloesungsstufen: Level 0 - keine Aufloesung  
                        Level 1 - direkte Aufloesung,keine Rekursion 
                        Level 2 - rekursive Aufloesung                    -->

<!-- Momentane Aufloesungsstufe Level 2  -->
<!-- Um die Rekursion anzuschalten bitte die Variable 'rekursion' auf 1 stellen -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
		xmlns:xql="http://metalab.unc.edu/xql"
		xmlns:xlink="http://www.w3.org/1999/xlink"
                xmlns:saxon="http://saxon.sf.net/"
		xmlns:xf="http://www.w3.org/2002/04/xquery-functions"
		xmlns:dbxlink="http://www.informatik.uni-freiburg.de/~malheiro/dbxlink"
		xmlns:xalan="http://xml.apache.org/xalan" version="1.0"> 

<xsl:output method="xml" indent="yes"/>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="rekursion">1</xsl:variable>
<xsl:variable name="root-document" select="saxon:systemId()"/>

<xsl:template match="/">
 <xsl:message> XSL(T) Stylesheet for Evaluating of linked XML-Documents Version 1.2 Final 
  </xsl:message>
 <xsl:message> Made as Prototype for Diploma Thesis by Dimitrio Malheiro </xsl:message>
 <xsl:message> --------------------------------------------------------- </xsl:message>
 <xsl:if test="$rekursion=1">
    <xsl:message> Rekursion angeschaltet </xsl:message> 
 </xsl:if>
 <xsl:message> Processing file ...Please wait! </xsl:message> 
 <xsl:comment> This file was generated by XSL(T) Stylesheet for xlink evaluation </xsl:comment>
 <xsl:comment> Stylesheet (c) by Dimitrio Malheiro in 2002 </xsl:comment>
 <xsl:variable name="root-elem" select="name(*)"/>
 <xsl:element name="{$root-elem}">      
   <xsl:apply-templates select="./*/*"/>   
   <xsl:call-template name="append"/> 
 </xsl:element> 			
 <xsl:message> File processed succesfully </xsl:message>
 <xsl:message> --------------------------------------------------------- </xsl:message>
 <xsl:message> Thank you for using </xsl:message> 
</xsl:template>

<!-- ******************************************************************************* -->
<!-- *************************** Template '*' ************************************** -->
<!-- ******************************************************************************* -->
<!-- +++ Auswertung aller Kindelemente und Buchfuehrung dieser. ++++++++++++++++++++ -->
<!-- +++ Unterscheidung zwischen tatsaechlichen Links (xlink:href) und               -->
<!-- +++ 'reinen' XPath-Ausdruecken. Das Ergbnis der Unterscheidung wird ausgewertet -->
<!-- +++ bzw. es wird ueberprueft, ob das aktuelle Element Kindelelemente besitzt,   -->
<!-- +++ die ein dbxlink:transparent='make-attribute' besitzen  ++++++++++++++++++++ --> 
<!-- +++ Tritt ein dbxlink:transparent Attribut auf, wird ein neues template         -->
<!-- +++ aufgerufen, welches die Verarbeitung vornimmt.                              -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template match="*">
<xsl:param name="oldstack"/>
<xsl:param name="url"><xsl:value-of select="$root-document"/></xsl:param> 
  <xsl:variable name="kind" select="name(.)"/>
  <xsl:if test="$rekursion=0">
    <xsl:if test="not(@dbxlink:transparent)">
    <xsl:element name="{$kind}">
      <xsl:for-each select="*[@dbxlink:transparent='make-attribute']">
       <xsl:variable name="ausgabe_werte">
        <xsl:choose>
         <xsl:when test="contains(@xlink:href,'#')">
           <xsl:value-of select="concat('document(',$apos,substring-before(@xlink:href,'#'),$apos,')'
								  ,substring-after(@xlink:href,'#'))"/> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@xlink:href"/> 
        </xsl:otherwise>
        </xsl:choose>
       </xsl:variable>
       <xsl:variable name="all-attributes" 
             select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:href') 
							  and not(name()='xlink:type')]"/>
       <xsl:variable name="the_id">
         <xsl:value-of select="generate-id(.)"/>
       </xsl:variable>
       <xsl:call-template name="generate-output">
         <xsl:with-param name="the_id" select="$the_id"/>
         <xsl:with-param name="ausgabe_werte" select="$ausgabe_werte"/>
         <xsl:with-param name="all-attrib" select="$all-attributes"/>
       </xsl:call-template>                      
          <xsl:variable name="dbxlink-elem" select="name(.)"/>
          <xsl:variable name="filename" select="concat($kind,'-',$dbxlink-elem,'.xml')"/>
	   <xsl:call-template name="Ids-speichern">
            <xsl:with-param name="dbxlink-elem" select="$dbxlink-elem"/>
            <xsl:with-param name="filename" select="$filename"/>
            <xsl:with-param name="the_id" select="$the_id"/>
          </xsl:call-template>
       </xsl:for-each>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="*"/>  
      <xsl:value-of select=".[not(*)]"/>
    </xsl:element>
  </xsl:if> 	
  <xsl:if test="@dbxlink:transparent">      		                		       
      <xsl:call-template name="dbxlink-auswertung"/>                            			      
       <xsl:apply-templates select="*"/>  
  </xsl:if> 
 </xsl:if>
  <xsl:if test="$rekursion=1">
   <xsl:variable name="position" select="generate-id(.)"/>
   <xsl:variable name="e-wert" select="substring-after($position,'e')"/>
   <xsl:variable name="identify" select="concat($url,'+',$e-wert)"/> 
   <xsl:choose>
   <xsl:when test="contains($oldstack,$identify)">
     <xsl:message> Element was just used </xsl:message>
   </xsl:when>
   <xsl:otherwise>
   <xsl:variable name="newstack" select="concat($oldstack,' ',$identify)"/>
   <xsl:if test="not(@dbxlink:transparent)">
    <xsl:element name="{$kind}">
      <xsl:for-each select="*[@dbxlink:transparent='make-attribute']">
       <xsl:variable name="kind-e-wert" select="substring-after(generate-id(.),'e')"/>
        <xsl:variable name="ausgabe_werte">
        <xsl:choose>
         <xsl:when test="contains(@xlink:href,'#')">
           <xsl:value-of 
                select="concat('document(',
                                 $apos,substring-before(@xlink:href,'#'),
                                 $apos,')',
                               substring-after(@xlink:href,'#'))"/> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@xlink:href"/>  
        </xsl:otherwise>
        </xsl:choose>
       </xsl:variable>
       <xsl:variable name="all-attributes" 
             select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:href') 
							  and not(name()='xlink:type')]"/>
       <xsl:variable name="the_id">
         <xsl:value-of select="generate-id(.)"/>
       </xsl:variable>
       <xsl:call-template name="generate-output">
         <xsl:with-param name="the_id" select="$the_id"/>
         <xsl:with-param name="ausgabe_werte" select="$ausgabe_werte"/>
         <xsl:with-param name="all-attrib" select="$all-attributes"/>
       </xsl:call-template>                      
          <xsl:variable name="dbxlink-elem" select="name(.)"/>
          <xsl:variable name="filename" select="concat($kind,'-',$dbxlink-elem,'.xml')"/>
	   <xsl:call-template name="Ids-speichern">
            <xsl:with-param name="dbxlink-elem" select="$dbxlink-elem"/>
            <xsl:with-param name="filename" select="$filename"/>
            <xsl:with-param name="the_id" select="$the_id"/>
          </xsl:call-template>
       </xsl:for-each>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="*">
       <xsl:with-param name="oldstack" select="$newstack"/>
      </xsl:apply-templates>
      <xsl:value-of select=".[not(*)]"/>
    </xsl:element>
  </xsl:if> 	
  <xsl:if test="@dbxlink:transparent">     
      <xsl:call-template name="dbxlink-auswertung">
        <xsl:with-param name="oldstack" select="$newstack"/>
      </xsl:call-template> 
   <!--  <xsl:apply-templates select="*"/>  -->
  </xsl:if> 
  </xsl:otherwise>
 </xsl:choose>
</xsl:if>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- ************************ Template 'dbxlink-auswertung' ************************ -->
<!-- ******************************************************************************* -->
<!-- +++ Je nach Wert des dbxlink:transparent Attributes wird ein entsprechendes     -->
<!-- +++ template aufgerufen, dass dann die Verarbeitung durchfuehrt                 -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="dbxlink-auswertung">
<xsl:param name="oldstack"/>

 <xsl:if test="contains(@dbxlink:transparent,'drop-element') 
           and contains(@dbxlink:transparent,'insert-elements')
           and ((@xlink:type='simple') or (@xlink:type='locator'))">
   <xsl:call-template name="insert-elements-with-drop">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
   </xsl:call-template>	  
 </xsl:if>

 <xsl:if test="contains(@dbxlink:transparent,'insert-contents') 
           and contains(@dbxlink:transparent,'drop-element')
           and ((@xlink:type='simple') or (@xlink:type='locator'))">
   <xsl:message> Error(1) dbxlink:transparent Value insert-contents and 
                 drop-element are not allowed together </xsl:message>
   <xsl:message> Element is: <xsl:value-of select="name(.)"/> </xsl:message>
 </xsl:if>

 <xsl:if test="contains(@dbxlink:transparent,'insert-contents') 
           and contains(@dbxlink:transparent,'keep-element')
           and ((@xlink:type='simple') or (@xlink:type='locator'))">
  <xsl:call-template name="keep-element-with-contents">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>  

 <xsl:if test="contains(@dbxlink:transparent,'insert-elements') 
           and contains(@dbxlink:transparent,'keep-element')
           and ((@xlink:type='simple') or (@xlink:type='locator'))">
  <xsl:call-template name="keep-element-with-elements">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if> 
     
 <xsl:if test="contains(@dbxlink:transparent,'keep-attributes') 
	   and contains(@dbxlink:transparent,'insert-elements') 
	   and contains(@dbxlink:transparent,'distribute') 
	   and ((@xlink:type='simple') or (@xlink:type='locator'))">
  <xsl:call-template name="keep-attributes-with-contents-dist">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>

 <xsl:if test="contains(@dbxlink:transparent,'keep-element') and (@xlink:type='extended')">
  <xsl:call-template name="extended-keep-element">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>

 <xsl:if test="contains(@dbxlink:transparent,'keep-element') 
           and contains(@dbxlink:transparent,'keep-from') 
	   and contains(@dbxlink:transparent,'keep-to')  
	   and (@xlink:type='arc')
	   and contains(@dbxlink:transparent,'from-contents')
	   and contains(@dbxlink:transparent,'to-contents')">
  <xsl:call-template name="arc-keep-element-keep-from-keep-to-tocontents-fromcontents">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>
    
 <xsl:if test="contains(@dbxlink:transparent,'keep-element') 
	   and contains(@dbxlink:transparent,'keep-from') 
	   and contains(@dbxlink:transparent,'keep-to')  
           and (@xlink:type='arc')
	   and contains(@dbxlink:transparent,'from-contents')
	   and contains(@dbxlink:transparent,'to-elements')">
  <xsl:call-template name="arc-keep-element-from-contents-to-elements">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>
    
 <xsl:if test="contains(@dbxlink:transparent,'keep-element') 
           and contains(@dbxlink:transparent,'keep-from') 
	   and contains(@dbxlink:transparent,'keep-to')  
	   and (@xlink:type='arc')
	   and contains(@dbxlink:transparent,'from-elements')
	   and contains(@dbxlink:transparent,'to-contents')">
  <xsl:call-template name="arc-keep-element-from-elements-to-contents">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>
    
 <xsl:if test="contains(@dbxlink:transparent,'keep-element')
	   and contains(@dbxlink:transparent,'keep-from') 
	   and contains(@dbxlink:transparent,'keep-to')  
	   and (@xlink:type='arc')
	   and contains(@dbxlink:transparent,'from-elements')
	   and contains(@dbxlink:transparent,'from-contents')">
  <xsl:call-template name="arc-keep-element-from-elements-to-elements">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>		   
 </xsl:if>
    
 <xsl:if test="contains(@dbxlink:transparent,'keep-element') 
	   and (@xlink:type='arc')
	   and contains(@dbxlink:transparent,'make-from-attribute')
	   and contains(@dbxlink:transparent,'make-to-attribute')"> 
  <xsl:call-template name="arc-keep-elem-make-from-make-to">
    <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>

 <xsl:if test="contains(@dbxlink:transparent,'keep-element') 
	   and contains(@dbxlink:transparent,'drop-from')
	   and contains(@dbxlink:transparent,'from-contents')
	   and contains(@dbxlink:transparent,'drop-to')
	   and contains(@dbxlink:transparent,'to-contents')
	   and (@dbxlink:from-role) and (@dbxlink:to-role)
	   and (@xlink:type='arc')">
  
  <xsl:call-template name="arc-from-role-to-role">
   <xsl:with-param name="oldstack" select="$oldstack"/> 
  </xsl:call-template>	
 </xsl:if>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- *********************Template 'Insert-Elements Drop-Element' ****************** -->
<!-- ******************************************************************************* -->
<!-- +++ Das aktuelle Element wird nicht in die Ergebnismenge hereingenommen,        -->
<!-- +++ sondern die Rueckgabewerte des Verfolgenten XPath-Ausdrucks werden          -->
<!-- +++ eingefuegt                        					     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="insert-elements-with-drop">
<xsl:param name="oldstack"/>
<xsl:variable name="ausgabe">
 <xsl:choose>
   <xsl:when test="contains(@xlink:href,'#')">
     <xsl:value-of select="concat('document(',$apos,substring-before(@xlink:href,'#'),$apos,')'
                                                           ,substring-after(@xlink:href,'#'))"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="@xlink:href"/>
   </xsl:otherwise>
  </xsl:choose>
</xsl:variable>
  <xsl:if test="$rekursion=0">
    <xsl:copy-of select="saxon:evaluate($ausgabe)"/>
  </xsl:if>
  <xsl:if test="$rekursion=1">
    <xsl:variable name="rueckgabe-wert">
	<xsl:copy-of select="saxon:evaluate($ausgabe)"/>
    </xsl:variable>
    <xsl:variable name="new-url" select="substring-before(@xlink:href,'#')"/>
    <xsl:apply-templates select="$rueckgabe-wert/*">
     <xsl:with-param name="url" select="$new-url"/>
     <xsl:with-param name="oldstack" select="$oldstack"/>
    </xsl:apply-templates>
  </xsl:if>
</xsl:template>

<!-- ******************************************************************************* --> 
<!-- ******************* Template 'Keep-Element insert-contents ******************** -->
<!-- ******************************************************************************* -->
<!-- +++ Das aktuelle Element wird beibehalten, wobei die xlink und dbxlink          -->
<!-- +++ Attribute eleminiert werden. Die Ruckgabewerte des verfolgten               -->
<!-- +++ XPath-Ausdrucks werden als Kinder eingefuegt, wobei das root-Element des    -->
<!-- +++ Rueckgabewertes ignoriert wird (nur die Kinder)                             -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->
<xsl:template name="keep-element-with-contents">
<xsl:param name="oldstack"/>
  <xsl:variable name="ausgabe">
    <xsl:choose>
     <xsl:when test="contains(@xlink:href,'#')">
      <xsl:value-of select="concat('document(',$apos,substring-before(@xlink:href,'#'),$apos,')'
                                                            ,substring-after(@xlink:href,'#'))"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="@xlink:href"/>
     </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:if test="$rekursion=0">
  <xsl:variable name="current-element" select="name(.)"/>
  <xsl:element name="{$current-element}">
  <xsl:choose>
   <xsl:when test="contains(@xlink:href,'#')">
       <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:href') 
								 and not(name()='xlink:type')]"/>
       <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe)"/>
       <xsl:copy-of select="$auswert-ergebnis/@*"/>
       <xsl:copy-of select="$auswert-ergebnis/*"/> 
   </xsl:when>
   <xsl:otherwise>
        <xsl:value-of select="saxon:evaluate($ausgabe)"/>
   </xsl:otherwise>
  </xsl:choose>
  </xsl:element>
  </xsl:if>
  <xsl:if test="$rekursion=1">
   <xsl:variable name="current-element" select="name(.)"/>
    <xsl:element name="{$current-element}">
      <xsl:choose>
        <xsl:when test="contains(@xlink:href,'#')">
         <xsl:variable name="new-url" select="substring-before(@xlink:href,'#')"/>
         <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:href') and not(name()='xlink:type')]"/>
         <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe)"/>
         <xsl:copy-of select="$auswert-ergebnis/@*"/>
         <xsl:apply-templates select="$auswert-ergebnis/*">
          <xsl:with-param name="oldstack" select="$oldstack"/>
          <xsl:with-param name="url" select="$new-url"/>
         </xsl:apply-templates>
        </xsl:when>
       <xsl:otherwise>
        <xsl:value-of select="saxon:evaluate($ausgabe)"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:element>
   </xsl:if>
</xsl:template>

<!-- ******************************************************************************* --> 
<!-- ************************ Template 'Keep-Element Insert-Elements' ************** -->
<!-- ******************************************************************************* -->
<!-- +++ Behalte das aktuelle Element und fuege die Ergebnismenge des ausgewerteten  -->
<!-- +++ XPath-Ausdrucks als Kind 						     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="keep-element-with-elements">
<xsl:param name="oldstack"/>
  <xsl:variable name="ausgabe">
  <xsl:choose>
     <xsl:when test="contains(@xlink:href,'#')">
      <xsl:value-of select="concat('document(',$apos,substring-before(@xlink:href,'#'),$apos,')',substring-after(@xlink:href,'#'))"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="@xlink:href"/>
     </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="current-element" select="name(.)"/>
    <xsl:element name="{$current-element}">
      <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:href') and not(name()='xlink:type')]"/>
      <xsl:if test="$rekursion=0">
       <xsl:copy-of select="saxon:evaluate($ausgabe)"/>
      </xsl:if>
      <xsl:if test="$rekursion=1">
       <xsl:variable name="new-url" select="substring-before(@xlink:href,'#')"/>
       <xsl:variable name="ergebnis" select="saxon:evaluate($ausgabe)"/>
       <xsl:apply-templates select="$ergebnis/*">
        <xsl:with-param name="oldstack" select="$oldstack"/>
        <xsl:with-param name="url" select="$new-url"/>
       </xsl:apply-templates>
      </xsl:if>
    </xsl:element>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- ********************** Template 'Keep-Attributes Insert-Contents Distribut' *** --> 
<!-- ******************************************************************************* -->
<!-- +++ Das aktuelle Element wird entfernt, jedoch werden diejenigen Attribute      -->
<!-- +++ behalten, die nicht dbxlink, xlink sind. Das erste Element der              -->
<!-- +++ Ergebnismenge wird dabei als root-Element genommen und die behaltenen       -->
<!-- +++ Attribute werden dem Element als Attribute zusaetzlich zu den eigenen       -->
<!-- +++ hinzugefuegt. Danach wird die restliche Ergebnismenge hinzugefuegt          -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="keep-attributes-with-contents-dist">
<xsl:param name="oldstack"/>
  <xsl:variable name="ausgabe">
  <xsl:choose>
     <xsl:when test="contains(@xlink:href,'#')">
      <xsl:value-of select="concat('document(',$apos,substring-before(@xlink:href,'#'),$apos,')',substring-after(@xlink:href,'#'))"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="@xlink:href"/>
     </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="new-url" select="substring-before(@xlink:href,'#')"/>
  <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe)"/>
  <xsl:variable name="the-attributes" select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:href') and not(name()='xlink:type')]"/>
   <xsl:for-each select="$auswert-ergebnis">
    <xsl:variable name="first-element-of-result" select="name($auswert-ergebnis/.)"/>
    <xsl:element name="{$first-element-of-result}">
     <xsl:copy-of select="$auswert-ergebnis/@*"/>
     <xsl:copy-of select="$the-attributes"/>
     <xsl:if test="$rekursion=0">
       <xsl:copy-of select="*"/>
     </xsl:if>
     <xsl:if test="$rekursion=1">
       <xsl:apply-templates select="*">
        <xsl:with-param name="url" select="$new-url"/>
        <xsl:with-param name="oldstack" select="$oldstack"/>
       </xsl:apply-templates>
     </xsl:if>
    </xsl:element>
  </xsl:for-each>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- ********************* Template 'Keep-Element' Type='extended' ***************** -->
<!-- ******************************************************************************* -->
<!-- +++ Das aktuelle Element und dessen Attribute bis auf die dbxlink und xlink     -->
<!-- +++ Attribute behalten bzw. einfuegen 					     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="extended-keep-element">
<xsl:param name="oldstack"/>
  <xsl:variable name="current-element" select="name(.)"/>
    <xsl:element name="{$current-element}">
      <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:type')]"/>
      <xsl:apply-templates select="*">
        <xsl:with-param name="oldstack" select="$oldstack"/>
      </xsl:apply-templates>
    </xsl:element>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- **************** Template 'Keep-Element keep-from from-contents *************** -->
<!-- **************** keep-to to-contents' Type='arc' ****************************** -->
<!-- ******************************************************************************* -->
<!-- +++ Behalte das aktuelle Element und dessen Attribute die nicht dbxlink, xlink  -->
<!-- +++ sind. Als erstes Kind wird zunaechst die Ergebnismenge des, im 	     -->
<!-- +++ xlink:from Attribut stehenden und dereferenzierten ids, eingefuegt          -->
<!-- +++ Als zweites Kind die Ergebnismenge des, im xlink:to Attribut stehenden ids  -->
<!-- +++ dereferenziert und eingefuegt.						     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="arc-keep-element-keep-from-keep-to-tocontents-fromcontents">
<xsl:param name="oldstack"/>
  <xsl:variable name="current-element" select="name(.)"/>
    <xsl:element name="{$current-element}">
      <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:type') 
					and not(name()='xlink:from') and not(name()='xlink:to')]"/>
	<xsl:element name="{name(id(@xlink:from))}">
	  <xsl:copy-of select="id(@xlink:from)/@*[not(name()='dbxlink:transparent')
				        and not(name()='xlink:href') and not(name()='xlink:type')]"/>
          <xsl:variable name="referenzed_href_from" select="id(@xlink:from)/@xlink:href"/>
          <xsl:variable name="new-url-from" select="substring-before((id(@xlink:from)/@xlink:href),'#')"/>
          <xsl:variable name="ausgabe_from">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_from,'#')">
  		 <xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_from,'#')
						 ,$apos,')',substring-after($referenzed_href_from,'#'))"/>
     	     </xsl:when>	  
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_from"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
	  <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe_from)"/>
	    <xsl:copy-of select="$auswert-ergebnis/@*"/>
            <xsl:if test="$rekursion=0">
	     <xsl:copy-of select="$auswert-ergebnis/*"/>
            </xsl:if>
	    <xsl:if test="$rekursion=1">
	     <xsl:apply-templates select="$auswert-ergebnis/*">
	      <xsl:with-param name="oldstack" select="$oldstack"/>
              <xsl:with-param name="url" select="$new-url-from"/>
	     </xsl:apply-templates>
            </xsl:if>
        </xsl:element>
        <xsl:element name="{name(id(@xlink:to))}">
	  <xsl:copy-of select="id(@xlink:to)/@*[not(name()='dbxlink:transparent') 
					    and not(name()='xlink:href') and not(name()='xlink:type')]"/>
	  <xsl:variable name="referenzed_href_to" select="id(@xlink:to)/@xlink:href"/>
          <xsl:variable name="new-url-to" select="substring-before((id(@xlink:to)/@xlink:href),'#')"/>
	  <xsl:variable name="ausgabe_to">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_to,'#')">
		<xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_to,'#')
						  ,$apos,')',substring-after($referenzed_href_to,'#'))"/>	
	     </xsl:when>
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_to"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
          <xsl:variable name="auswert-ergebnis_to" select="saxon:evaluate($ausgabe_to)"/>
	    <xsl:copy-of select="$auswert-ergebnis_to/@*"/>
            <xsl:if test="$rekursion=0">
       	      <xsl:copy-of select="$auswert-ergebnis_to/*"/>
	    </xsl:if>
	    <xsl:if test="$rekursion=1">
	      <xsl:apply-templates select="$auswert-ergebnis_to/*">
	       <xsl:with-param name="oldstack" select="$oldstack"/>
               <xsl:with-param name="url" select="$new-url-to"/>
	     </xsl:apply-templates>
            </xsl:if>
        </xsl:element>
    </xsl:element>
</xsl:template>


<!-- ******************************************************************************* -->
<!-- ***************** Template 'Keep-Element make-from-attribut ******************* -->       
<!-- ***************** make-to-attribut ******************************************** -->
<!-- ******************************************************************************* -->
<!-- +++ Behalte das aktuelle Element bis auf die Attribute xlink, dbxlink und       -->      
<!-- +++ erzeuge neue Attribute wobei der Name aus der Dereferenzierung des ids      -->
<!-- +++ des xlink:from bzw. des xlink:to gebildetet wird (Name des idref Elements)  -->
<!-- +++ Fuege alle Kinder ein 							     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="arc-keep-elem-make-from-make-to">
<xsl:param name="oldstack"/>
  <xsl:variable name="current-element" select="name(.)"/>
    <xsl:element name="{$current-element}">
      <xsl:attribute name="{name(id(@xlink:from))}">
	<xsl:value-of select="@xlink:from"/>
      </xsl:attribute>
      <xsl:attribute name="{name(id(@xlink:to))}">
	<xsl:value-of select="@xlink:to"/>
      </xsl:attribute>
      <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:type')
				  and not(name()='xlink:from') and not(name()='xlink:to')]"/>
      <xsl:if test="$rekursion=0">
       <xsl:copy-of select="*"/>
      </xsl:if>
      <xsl:if test="$rekursion=1">
	<xsl:apply-templates select="*">
	 <xsl:with-param name="oldstack" select="$oldstack"/>
	</xsl:apply-templates>
      </xsl:if>
    </xsl:element>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- ******************** Template 'Keep-Element From-Contents ********************* -->
<!-- ********************           to-elements'               ********************* -->
<!-- ******************************************************************************* -->
<!-- +++ Behalte das Element mit den Attributen die nicht xlink oder dbxlink sind    -->
<!-- +++ Erzeuge ein Element dessen Namen der Name des Dereferenzierten xlink:from   -->
<!-- +++ Attributes ist. Behalte auch dessen Attribute die nicht xlink oder dbxlink  -->
<!-- +++ sind. Werte den Wert des xlink:href Attributes aus dem Element aus, zu dem  -->
<!-- +++ die Dereferenzierung fuehrt. Fuege die Attribute die nicht xlink oder       -->
<!-- +++ dbxlink aus der Ergebnismenge ein. Fuege die Kinder aus der Ergebnismenge   -->
<!-- +++ ein. (ohne oberstes Element) 						     -->
<!-- +++ Analog fuer xlink:to jedoch mit oberstem Element			     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* -->

<xsl:template name="arc-keep-element-from-contents-to-elements">
<xsl:param name="oldstack"/>
<xsl:variable name="current-element" select="name(.)"/>
  <xsl:element name="{$current-element}">
   <xsl:copy-of select="@*[not(name()='dbxlink:transparent') 
	and not(name()='xlink:type') and not(name()='xlink:from') and not(name()='xlink:to')]"/>
   <xsl:element name="{name(id(@xlink:from))}">
    <xsl:copy-of select="id(@xlink:from)/@*[not(name()='dbxlink:transparent') 
        and not(name()='xlink:href') and not(name()='xlink:type')]"/>
    <xsl:variable name="referenzed_href_from" select="id(@xlink:from)/@xlink:href"/>
    <xsl:variable name="new-url-from" select="substring-before((id(@xlink:from)/@xlink:href),'#')"/>
    <xsl:variable name="ausgabe_from">
      <xsl:choose>
       <xsl:when test="contains($referenzed_href_from,'#')">
        <xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_from,'#')
					   ,$apos,')',substring-after($referenzed_href_from,'#'))"/>
       </xsl:when>	  
       <xsl:otherwise>
        <xsl:value-of select="$referenzed_href_from"/>
       </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe_from)"/>
    <xsl:copy-of select="$auswert-ergebnis/@*"/>
    <xsl:if test="$rekursion=0">
     <xsl:copy-of select="$auswert-ergebnis/*"/>
    </xsl:if>
    <xsl:if test="$rekursion=1">
     <xsl:apply-templates select="$auswert-ergebnis/*">
      <xsl:with-param name="oldstack" select="$oldstack"/>
      <xsl:with-param name="url" select="$new-url-from"/>
     </xsl:apply-templates>
    </xsl:if>   
  </xsl:element>
	
  <xsl:element name="{name(id(@xlink:to))}">
   <xsl:copy-of select="id(@xlink:to)/@*[not(name()='dbxlink:transparent') 
		    and not(name()='xlink:href') and not(name()='xlink:type')]"/>
   <xsl:variable name="referenzed_href_to" select="id(@xlink:to)/@xlink:href"/>
   <xsl:variable name="new-url-to" select="substring-before((id(@xlink:to)/@xlink:href),'#')"/>
   <xsl:variable name="ausgabe_to">
    <xsl:choose>
     <xsl:when test="contains($referenzed_href_to,'#')">
      <xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_to,'#')
			  ,$apos,')',substring-after($referenzed_href_to,'#'))"/>	
     </xsl:when>
     <xsl:otherwise>
       <xsl:value-of select="$referenzed_href_to"/>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:variable>
   <xsl:variable name="auswert-ergebnis_to" select="saxon:evaluate($ausgabe_to)"/>
    <xsl:if test="$rekursion=0">
     <xsl:copy-of select="$auswert-ergebnis_to/."/>
    </xsl:if>
    <xsl:if test="$rekursion=1">
     <xsl:copy-of select="$auswert-ergebnis_to/.[not(*)]"/>
     <xsl:apply-templates select="$auswert-ergebnis_to/*">
      <xsl:with-param name="oldstack" select="$oldstack"/>
      <xsl:with-param name="url" select="$new-url-to"/>
     </xsl:apply-templates>
    </xsl:if> 
  </xsl:element>
 </xsl:element>
</xsl:template>	

<!-- ******************************************************************************* -->
<!-- ********************** Template 'Keep-Element From-Elements ******************* -->
<!-- ********************** to-contents 			 ******************* -->
<!-- ******************************************************************************* -->
<!-- +++ Behalte das aktuelle Element mit seinen Attributen ausser xlink und dbxlink -->
<!-- +++ Erzeuge ein Element dessen Namen der Name des Dereferenzierten xlink:from   -->
<!-- +++ Attributes ist. Behalte auch dessen Attribute die nicht xlink oder dbxlink  -->
<!-- +++ sind. Fuege die Ergebnismenge aus der Auswertung des xlink:href Attributes  -->
<!-- +++ komplet ein.(inkl. obererstes Element)					     -->
<!-- +++ Analog fuer xlink:to jedoch ohne oberstes Element aus der Ergebnismenge     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* --> 

<xsl:template name="arc-keep-element-from-elements-to-contents">
<xsl:param name="oldstack"/>
<xsl:variable name="current-element" select="name(.)"/>
    <xsl:element name="{$current-element}">
      <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:type') 
					and not(name()='xlink:from') and not(name()='xlink:to')]"/>
	<xsl:element name="{name(id(@xlink:from))}">
	  <xsl:copy-of select="id(@xlink:from)/@*[not(name()='dbxlink:transparent') 
					and not(name()='xlink:href') and not(name()='xlink:type')]"/>
          <xsl:variable name="referenzed_href_from" select="id(@xlink:from)/@xlink:href"/>
          <xsl:variable name="ausgabe_from">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_from,'#')">
  		 <xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_from,'#')
					,$apos,')',substring-after($referenzed_href_from,'#'))"/>
     	     </xsl:when>	  
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_from"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
	  <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe_from)"/>
         <xsl:if test="$rekursion=0">
           <xsl:copy-of select="$auswert-ergebnis/."/>
         </xsl:if>
         <xsl:if test="$rekursion=1">
	   <xsl:copy-of select="$auswert-ergebnis/.[not(*)]"/>
           <xsl:apply-templates select="$auswert-ergebnis/*">
     	    <xsl:with-param name="oldstack" select="$oldstack"/>
	    <xsl:with-param name="url" select="substring-before($referenzed_href_from,'#')"/>
           </xsl:apply-templates>
         </xsl:if>
        </xsl:element>
	<xsl:element name="{name(id(@xlink:to))}">
	  <xsl:copy-of select="id(@xlink:to)/@*[not(name()='dbxlink:transparent') 
					and not(name()='xlink:href') and not(name()='xlink:type')]"/>
	  <xsl:variable name="referenzed_href_to" select="id(@xlink:to)/@xlink:href"/>
	  <xsl:variable name="ausgabe_to">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_to,'#')">
		<xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_to,'#')
					      ,$apos,')',substring-after($referenzed_href_to,'#'))"/>	
	     </xsl:when>
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_to"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
          <xsl:variable name="auswert-ergebnis_to" select="saxon:evaluate($ausgabe_to)"/>
	  <xsl:copy-of select="$auswert-ergebnis_to/@*"/>
          <xsl:if test="$rekursion=0">
           <xsl:copy-of select="$auswert-ergebnis_to/*"/>
          </xsl:if>
	  <xsl:if test="$rekursion=1">
	   <xsl:apply-templates select="$auswert-ergebnis_to/*">
             <xsl:with-param name="oldstack" select="$oldstack"/>
	     <xsl:with-param name="url" select="substring-before($referenzed_href_to,'#')"/>
           </xsl:apply-templates>
          </xsl:if>
        </xsl:element>
    </xsl:element>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- ********************** Template 'Keep-Element From-Elements ******************* -->
<!-- ********************** to-elements 			 ******************* -->
<!-- ******************************************************************************* -->
<!-- +++ Behalte das aktuelle Element mit seinen Attributen ausser xlink und dbxlink -->
<!-- +++ Erzeuge ein Element dessen Namen der Name des Dereferenzierten xlink:from   -->
<!-- +++ Attributes ist. Behalte auch dessen Attribute die nicht xlink oder dbxlink  -->
<!-- +++ sind. Fuege die Ergebnismenge aus der Auswertung des xlink:href Attributes  -->
<!-- +++ komplet ein.(inkl. obererstes Element)					     -->
<!-- +++ Analog fuer xlink:to inklusive oberstes Element aus der Ergebnismenge       -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* --> 

<xsl:template name="arc-keep-element-from-elements-to-elements">
<xsl:param name="oldstack"/>
<xsl:variable name="current-element" select="name(.)"/>
    <xsl:element name="{$current-element}">
      <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:type') 
					and not(name()='xlink:from') and not(name()='xlink:to')]"/>
	<xsl:element name="{name(id(@xlink:from))}">
	  <xsl:copy-of select="id(@xlink:from)/@*[not(name()='dbxlink:transparent') 
					and not(name()='xlink:href') and not(name()='xlink:type')]"/>
          <xsl:variable name="referenzed_href_from" select="id(@xlink:from)/@xlink:href"/>
          <xsl:variable name="ausgabe_from">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_from,'#')">
  		 <xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_from,'#')
					    ,$apos,')',substring-after($referenzed_href_from,'#'))"/>
     	     </xsl:when>	  
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_from"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
	  <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe_from)"/>
		<xsl:if test="$rekursion=0">
            	  <xsl:copy-of select="$auswert-ergebnis/."/>
   		</xsl:if>
		<xsl:if test="$rekursion=1">
		  <xsl:copy-of select="$auswert-ergebnis/.[not(*)]"/>
	          <xsl:apply-templates select="$auswert-ergebnis/*">
         	    <xsl:with-param name="oldstack" select="$oldstack"/>
		    <xsl:with-param name="url" select="substring-before($referenzed_href_from,'#')"/>
	          </xsl:apply-templates>
                </xsl:if> 
        </xsl:element>
	<xsl:element name="{name(id(@xlink:to))}">
	  <xsl:copy-of select="id(@xlink:to)/@*[not(name()='dbxlink:transparent') 
					and not(name()='xlink:href') and not(name()='xlink:type')]"/>
	  <xsl:variable name="referenzed_href_to" select="id(@xlink:to)/@xlink:href"/>
	  <xsl:variable name="ausgabe_to">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_to,'#')">
		<xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_to,'#')
					      ,$apos,')',substring-after($referenzed_href_to,'#'))"/>	
	     </xsl:when>
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_to"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
          <xsl:variable name="auswert-ergebnis_to" select="saxon:evaluate($ausgabe_to)"/>
            <xsl:if test="$rekursion=0">
	     <xsl:copy-of select="$auswert-ergebnis_to/."/>
	    </xsl:if>
	    <xsl:if test="$rekursion=1">
		  <xsl:copy-of select="$auswert-ergebnis_to/.[not(*)]"/>
	          <xsl:apply-templates select="$auswert-ergebnis_to/*">
         	    <xsl:with-param name="oldstack" select="$oldstack"/>
		    <xsl:with-param name="url" select="substring-before($referenzed_href_to,'#')"/>
	          </xsl:apply-templates>
                </xsl:if> 
        </xsl:element>
    </xsl:element>
</xsl:template>

<!-- ******************************************************************************* -->
<!-- ********************** Template 'From-Role To-Role          ******************* -->
<!-- ******************************************************************************* -->
<!-- +++ Behalte das aktuelle Element mit seinen Attributen ausser xlink und dbxlink -->
<!-- +++ Erzeuge ein Element dessen Name durch den Wert des Attributs                --> 
<!-- +++ dbxlink:from-role bestimmt wird.                                            -->
<!-- +++ Behalte auch dessen Attribute die nicht xlink oder dbxlink                  -->
<!-- +++ sind. Fuege die Ergebnismenge aus der Auswertung des xlink:href Attributes  -->
<!-- +++ komplet ein.(exkl. obererstes Element)					     -->
<!-- +++ Analog fuer xlink:to und dbxlink:to-role 				     -->
<!-- ******************************************************************************* -->
<!-- ******************************************************************************* --> 


<xsl:template name="arc-from-role-to-role">
<xsl:param name="oldstack"/>
<xsl:variable name="current-element" select="name(.)"/>
 <xsl:element name="{$current-element}">
 <xsl:copy-of select="@*[not(name()='dbxlink:transparent') and not(name()='xlink:type') 
				and not(name()='xlink:from') 
				and not(name()='xlink:to') and not(name()='dbxlink:from-role') 
				and not(name()='dbxlink:to-role')]"/>
   <xsl:variable name="from-role-wert" select="@dbxlink:from-role"/>
   <xsl:element name="{$from-role-wert}">
     <xsl:copy-of select="id(@xlink:from)/@*[not(name()='dbxlink:transparent') 
				and not(name()='xlink:href') and not(name()='xlink:type')]"/>
     <xsl:variable name="referenzed_href_from" select="id(@xlink:from)/@xlink:href"/>
          <xsl:variable name="ausgabe_from">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_from,'#')">
  		 <xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_from,'#')
				,$apos,')',substring-after($referenzed_href_from,'#'))"/>
     	     </xsl:when>	  
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_from"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
	  <xsl:variable name="auswert-ergebnis" select="saxon:evaluate($ausgabe_from)"/>
  		<xsl:copy-of select="$auswert-ergebnis/@*"/>
 		<xsl:if test="$rekursion=0">
                 <xsl:copy-of select="$auswert-ergebnis/*"/>
		</xsl:if>
		<xsl:if test="$rekursion=1">
		 <xsl:apply-templates select="$auswert-ergebnis/*">
		  <xsl:with-param name="oldstack" select="$oldstack"/>
		  <xsl:with-param name="url" select="substring-before($referenzed_href_from,'#')"/>
		 </xsl:apply-templates>
	        </xsl:if>
        </xsl:element>
   <xsl:variable name="to-role-wert" select="@dbxlink:to-role"/>
   <xsl:element name="{$to-role-wert}">
     <xsl:copy-of select="id(@xlink:to)/@*[not(name()='dbxlink:transparent') 
				and not(name()='xlink:href') and not(name()='xlink:type')]"/>
	  <xsl:variable name="referenzed_href_to" select="id(@xlink:to)/@xlink:href"/>
	  <xsl:variable name="ausgabe_to">
            <xsl:choose>
	     <xsl:when test="contains($referenzed_href_to,'#')">
		<xsl:value-of select="concat('document(',$apos,substring-before($referenzed_href_to,'#')
				,$apos,')',substring-after($referenzed_href_to,'#'))"/>	
	     </xsl:when>
	     <xsl:otherwise>
               <xsl:value-of select="$referenzed_href_to"/>
	     </xsl:otherwise>
    	    </xsl:choose>
  	  </xsl:variable>
          <xsl:variable name="auswert-ergebnis_to" select="saxon:evaluate($ausgabe_to)"/>
	    <xsl:copy-of select="$auswert-ergebnis_to/@*"/>
	    <xsl:if test="$rekursion=0">
             <xsl:copy-of select="$auswert-ergebnis_to/*"/>
	    </xsl:if>
	    <xsl:if test="$rekursion=1">
	     <xsl:apply-templates select="$auswert-ergebnis_to/*">
	      <xsl:with-param name="oldstack" select="$oldstack"/>
	      <xsl:with-param name="url" select="substring-before($referenzed_href_to,'#')"/>
	     </xsl:apply-templates>
	    </xsl:if>
    </xsl:element>
  </xsl:element>
 </xsl:template>

<!-- ******************************************************************************* -->
<!-- ************************Methoden fuer make-attribut *************************** -->
<!-- ******************************************************************************* -->


<xsl:template name="generate-output">
  <xsl:param name="the_id"/>
  <xsl:param name="ausgabe_werte"/>
  <xsl:param name="all-attrib"/>
  <xsl:variable name="outputname" select="concat('temp-',$the_id,'.xml')"/>
          <xsl:result-document href="{$outputname}">
	      <xsl:variable name="ausgabe_erg" select="saxon:evaluate($ausgabe_werte)"/>
              <xsl:variable name="wurzel" select="name($ausgabe_erg/.)"/>
              <xsl:element name="{$wurzel}">
                <xsl:attribute name="id">
                  <xsl:value-of select="$the_id"/>
                </xsl:attribute>
                <xsl:copy-of select="$all-attrib"/>
                <xsl:copy-of select="$ausgabe_erg/@*"/>
                <xsl:copy-of select="$ausgabe_erg/*"/>
              </xsl:element>    
          </xsl:result-document>  
</xsl:template> 

<xsl:template name="append">
  <xsl:for-each select="./*">
    <xsl:if test="@dbxlink:transparent='make-attribute'">
      <xsl:variable name="the_id">
         <xsl:value-of select="generate-id(.)"/>
      </xsl:variable>
      <xsl:call-template name="append_with_generated_name">
            <xsl:with-param name="the_id" select="$the_id"/>
      </xsl:call-template>
    </xsl:if>
   <xsl:call-template name="append"/>
  </xsl:for-each>
</xsl:template>

<xsl:template name="append_with_generated_name">
  <xsl:param name="the_id"/>   
        <xsl:variable name="outputname" select="concat('temp-',$the_id,'.xml')"/>
        <xsl:variable name="out-doc" select="concat('document(',$apos,$outputname,$apos,')/.')"/>
        <xsl:copy-of select="saxon:evaluate($out-doc)"/> 
</xsl:template>

<xsl:template name="Ids-speichern">
<xsl:param name="dbxlink-elem"/>
<xsl:param name="filename"/>    
<xsl:param name="the_id"/>   
          <xsl:choose>
           <xsl:when test="preceding-sibling::*/name()=name(.) or following-sibling::*/name()=name(.)">
              <xsl:attribute name="{$dbxlink-elem}">
                 <xsl:variable name="elemname" select="name(.)"/> 
                 <xsl:for-each select="../*[name()=$elemname]">
                  <xsl:variable name="many_ids">
                       <xsl:value-of select="generate-id(.)"/>
                  </xsl:variable>       
                  <xsl:variable name="format_output" select="concat($many_ids,' ')"/>
                  <xsl:value-of select="$format_output"/>
                 </xsl:for-each>
              </xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
              <xsl:attribute name="{$dbxlink-elem}"> 
	      <xsl:value-of select="$the_id"/>
              </xsl:attribute>
           </xsl:otherwise>
          </xsl:choose>       
</xsl:template>

</xsl:stylesheet>
