<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
  extension-element-prefixes="saxon"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="XSL"
  xmlns:saxon="http://saxon.sf.net/"
>
<!-- This file is used to translate make rules given in a short text format (vmake) to a eclipse.ANT script.
  In this file all possible generating algorithm should be known. The selecting routine is contained in the first
    template match="....Xmake",
  look for >>>xsl:when test="@translator=<<<.
  All other xsl:template are matching to the several rules
  -->
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:param name="ctrl" select="'?'" /><!-- it is a control parameter from outside. -->
<xsl:param name="tmp" select="'../tmp'" /><!-- it is a control parameter from outside. -->

<xsl:variable name="curDir"><xsl:text>${curDir}</xsl:text></xsl:variable>
<xsl:variable name="env.XML_TOOLBASE"><xsl:text>${env.XML_TOOLBASE}</xsl:text></xsl:variable>
<xsl:variable name="Classpath"><xsl:text>-cp
  ${env.ECLIPSE_CP};${env.XML_TOOLBASE}/xslt.jar;${env.XML_TOOLBASE}/jdom.jar</xsl:text></xsl:variable>
<xsl:variable name="ClasspathSaxon"><xsl:text>-cp
  ${env.ECLIPSE_CP};${env.XML_TOOLBASE}/xslt.jar;${env.XML_TOOLBASE}/jdom.jar;${env.XML_TOOLBASE}/saxon8.jar;${env.XML_T
  OLBASE}/saxon8-jdom.jar</xsl:text></xsl:variable>
  
 
 
 
<!-- ROOT TEMPLATE ************************************************************************************************-->  
   
<xsl:template match= "/root/Xmake | /Xmake">
<project name="XmakeAnt" default="XmakeAnt" basedir=".">
<taskdef name="Zcopy" classname="org.vishia.ant.Zcopy" />
<property environment="env" />

<property name="tmp" value="{$tmp}" />

<xsl:variable name="depends">
  <xsl:for-each select="target">
    <xsl:variable name="targetName"><xsl:call-template name="targetName" /></xsl:variable>
    <xsl:text>(?$targetName?)(?if "last()>position()"?),(?/if?)</xsl:text><!-- The first output file determines the name
      of the template. -->
  </xsl:for-each>
</xsl:variable>

<target name="XmakeAnt" description="The whole xmake">
  <echo message="current dir: {'${curDir}'}" />
  <antcall target="XmakeAnt1"/>
</target>


<target name="XmakeAnt1" description="The whole xmake"
	depends="{$depends}" >
</target>

<!-- The loop for all founded target in input -->
<xsl:for-each select="target">
  <xsl:text>
    
    
    
  </xsl:text>
  <xsl:variable name="targetfile"><xsl:for-each select="output"><xsl:call-template name="absPathfile"
    /></xsl:for-each></xsl:variable>
  <!-- targets without isUptodate and wiht special target frame: -->  
  <xsl:choose><xsl:when test="@translator='zbnfCheader'"><xsl:call-template name="zbnfCheader"/>
  </xsl:when><xsl:when test="@translator='genXmiFromZbnfCheader'"><xsl:call-template name="genXmiFromZbnfCheader"/>
  </xsl:when><xsl:when test="@translator='file2Html'"><xsl:call-template name="file2Html"/>
  </xsl:when><xsl:when test="@translator='stdMake' or @translator='msMake'">
    <xsl:call-template name="genTargetWithAvaileableTestFirstInput_UptodateAllInput">
      <xsl:with-param name="genExec" select="@translator" />
      <xsl:with-param name="targetfile" select="$targetfile" />
    </xsl:call-template>
  </xsl:when><xsl:when test="@translator='copyNewerFiles'"><xsl:call-template name="copyNewerFiles"/>
  </xsl:when><xsl:when test="@translator='copyFiles'"><xsl:call-template name="copyFiles"/>
  </xsl:when><xsl:when test="@translator='copyChangedFiles'"><xsl:call-template name="copyChangedFiles"/>
  </xsl:when><xsl:otherwise>
    <!-- targets with isUptodate and common target frame: -->  
    <xsl:variable name="targetName"><xsl:call-template name="targetName" /></xsl:variable>
    <xsl:variable name="isUptodate"><xsl:text>isUptodate_</xsl:text><xsl:value-of select="$targetName" /></xsl:variable>
    <target name="{$targetName}">
    <xsl:if test="input" >
      <xsl:attribute name="depends"><xsl:value-of select="$isUptodate" /></xsl:attribute>
      <xsl:attribute name="unless"><xsl:value-of select="$isUptodate" /></xsl:attribute>
    </xsl:if>
      
      <!-- depends="{$isUptodate}" unless="{$isUptodate}" -->
      <xsl:choose><xsl:when test="@translator='genMsg_h'"><xsl:call-template name="genMsg_h"/>
      </xsl:when><xsl:when test="@translator='genReflection'">
        <xsl:call-template name="genReflection">
        <xsl:with-param name="targetfile" select="$targetfile" />
      </xsl:call-template>
      </xsl:when><xsl:when test="@translator='genReflectionFromHeader'"><xsl:call-template
        name="genReflectionFromHeader"/>
      </xsl:when><xsl:when test="@translator='genXmiFromHeader2'"><xsl:call-template name="genXmiFromHeader2"/>
      </xsl:when><xsl:when test="@translator='genXmiFromHeader'"><xsl:call-template name="genXmiFromHeaderTarget"/>
      </xsl:when><xsl:when test="@translator='CHeader2JavaByteCoding'"><xsl:call-template
        name="CHeader2JavaByteCoding"/>
      </xsl:when><xsl:when test="@translator='zipFiles'"><xsl:call-template name="zipFiles"/>
      </xsl:when><xsl:otherwise><echo message="no rule found for {@translator}" />
      </xsl:otherwise></xsl:choose>    
    </target>
  
    <xsl:if test="input" >
    <target name="{$isUptodate}" >
      <uptodate property="{$isUptodate}" targetfile="{$targetfile}">
        <xsl:call-template name="evaluateInput">
          <xsl:with-param name="call" select="'uptodateSource'" />
        </xsl:call-template>
      </uptodate> 
    </target>
    </xsl:if>
  </xsl:otherwise></xsl:choose>

</xsl:for-each>

</project>

</xsl:template>


<!-- This template translates a Zmake-expression like
  
       tmp/*.zbnf.xml := file2Html($Headerfiles);
  
     in some targets to translate the individually files from special text formats to html readable text.
     a common target is build with the depends of all some translating targets.
 -->
<xsl:template name="file2Html">
  <xsl:call-template name="genTargetForEachInput">
    <xsl:with-param name="genExecForEachInput" select="'exec_file2Html'" />
    <xsl:with-param name="xmlTool_srcFiles" >
      <srcfiles file="{'${env.XML_TOOLBASE}/Xslt.jar'}" />
    </xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template name="exec_file2Html">
<xsl:param name="targetfile" />  
<xsl:param name="srcfile" />
<xsl:param name="xmlInputNode" />
<xsl:param name="xmlTargetNode" />
  <echo message="gen HTML" />
  <exec dir="{$curDir}" executable= "java" failonerror="false">
    <xsl:variable name="i"><xsl:text>-i</xsl:text><xsl:value-of select="@srcpath" /><xsl:text>/</xsl:text><xsl:value-of
      select="@srcfile" /></xsl:variable>
    <xsl:variable name="o"><xsl:text>-o../html/</xsl:text><xsl:value-of select="@srcfile" /><xsl:value-of
      select="@dstext"/></xsl:variable>
    <arg line="{$Classpath}" />
    <arg line ="{'org.vishia.xml.Textfile2Html'}" />
    <arg line="{'-i'}{$srcfile}" />
    <arg line="{'-o'}{$targetfile}" />
  </exec>
</xsl:template>








<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="genMsg_h">
  <echo message="XmakeAnt.xslp template genMsg_: generate {output/@path}{output/@file}" />
  <echo message="input: {input/@path}{input/@file}.xml" />
  <echo message="XML_TOOLBASE=${'{env.XML_TOOLBASE}'}/xslt.jar" />
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <xsl:variable name="i"><xsl:text>-i</xsl:text><xsl:value-of select="@srcpath" /><xsl:text>/</xsl:text><xsl:value-of
      select="@srcfile" /></xsl:variable>
    <xsl:variable name="o"><xsl:text>-o../html/</xsl:text><xsl:value-of select="@srcfile" /><xsl:value-of
      select="@dstext"/></xsl:variable>
    <xsl:variable name="s"><xsl:text>-o../html/</xsl:text><xsl:value-of select="@srcfile" /><xsl:value-of
      select="@dstext"/></xsl:variable>
    <arg line="{$Classpath}" />
    <arg line ="org.vishia.zbnfXml.Zbnf2Xml" />
	  <arg line="-i{input/@path}{input/@file}{input/@ext}" />
    <arg line="-s{'${env.XML_TOOLBASE}'}/XslTRA/OamMessages.sbnf" />
	  <arg line="-y{'${tmp}'}/{input/@file}.sbnf.xml" />
  </exec>
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$Classpath}" />
    <arg line ="org.vishia.xml.Xsltpre" />
	  <arg line="-i{'${env.XML_TOOLBASE}'}/XslTRA/OamMessages_WinCC.xslp" />
	  <arg line="-o{'${env.XML_TOOLBASE}'}/XslTRA/gen/OamMessages_WinCC.xsl" />
  </exec>
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$Classpath}{';${env.XML_TOOLBASE}/saxon8.jar'}" />
    <arg line ="net.sf.saxon.Transform" />
	  <arg line="-o {output/@path}{output/@file}.h" />
	  <arg line="{'${tmp}'}/{input/@file}.sbnf.xml" />
	  <arg line="{'${env.XML_TOOLBASE}'}/XslTRA/gen/OamMessages_WinCC.xsl" />
  </exec>
</xsl:template>



<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="genReflectionFromHeader">
  <echo message="gen Reflection from Header" />
  <!-- ZBNFparser-->
  <xsl:for-each select="input">
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$Classpath}" />
      <arg line ="org.vishia.zbnfXml.Zbnf2Xml" />
	    <xsl:variable name="i"><xsl:text>-i:(?@pathbase?)(?if
  "@pathbase"?)/(?/if?)(?@path?)(?@file?)(?@ext?)</xsl:text></xsl:variable>
      <arg line="{$i}" />
	    <arg line="{'-s:${env.XML_TOOLBASE}/Sbnf2Xml/Cheader.sbnf'}" />
      <xsl:variable name="o"><xsl:text>-y:${tmp}/(?@file?)zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$o}" />
      <xsl:variable name="file"><xsl:text>-a:@filename="(?@path?)(?@file?)"</xsl:text></xsl:variable>
      <arg line="{$file}" />
    </exec>
  </xsl:for-each>
  <!-- generate .types.xml -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="org.vishia.xml.Xslt" />
	  <xsl:for-each select="input">
      <xsl:variable name="i"><xsl:text>-i${tmp}/(?@file?)zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$i}" />
    </xsl:for-each>  
    <arg line="{'-t${env.XML_TOOLBASE}/XmlDocu_xsl/HeaderXmlDissolveTypes.xsl'}" />
    <arg line="-w+" />
	  <xsl:variable name="o"><xsl:text>-y${tmp}/(?@file?)types.xml</xsl:text></xsl:variable>
    <arg line="{$o}" />
  </exec>
  <!-- generate XMI -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="org.vishia.xml.Xslt" />
	  <xsl:for-each select="input">
      <xsl:variable name="i"><xsl:text>-i${tmp}/(?@file?)zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$i}" />
    </xsl:for-each>  
	  <xsl:variable name="iTypes"><xsl:text>-i${tmp}/(?@file?)types.xml</xsl:text></xsl:variable>
    <arg line="{$iTypes}" />
    <arg line="{'-t${env.XML_TOOLBASE}/XmlDocu_xsl/HeaderXml2Xmi.xsl'}" />
    <arg line="-w+" />
	  <xsl:variable name="y"><xsl:text>-y${tmp}/(?!output/@file?).xmi</xsl:text></xsl:variable>
    <arg line="{$y}" />
  </exec>
  <!-- generate Xmi2Reflection.xsl -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$Classpath}" />
    <arg line ="org.vishia.xml.Xsltpre" />
	  <arg line="{'-i${env.XML_TOOLBASE}/XmlDocu_xsl/Xmi2Reflection.xslp'}" />
	  <arg line="{'-o${env.XML_TOOLBASE}/XmlDocu_xsl/gen/Xmi2Reflection.xsl'}" />
  </exec>
  <!-- generate Reflection from XMI -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="net.sf.saxon.Transform" />
	  <xsl:variable name="s"><xsl:text>-s ${tmp}/(?!output/@file?).xmi</xsl:text></xsl:variable>
    <arg line="{$s}" />
	  <arg line="{'${env.XML_TOOLBASE}/XmlDocu_xsl/gen/Xmi2Reflection.xsl'}" />
    <xsl:variable name="UmlComponent"><xsl:text>ReflectionName="(?!output/@file?)"
      UmlComponent="Header"</xsl:text></xsl:variable>
    <arg line="{$UmlComponent}" />
    <xsl:variable name="Outputfile"><xsl:text>Outputfile="(?!output/@file?)"</xsl:text></xsl:variable>
    <arg line="{$Outputfile}" />
  </exec>
  <!--
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <xsl:variable name="i"><xsl:text>-i</xsl:text><xsl:value-of select="@srcpath" /><xsl:text>/</xsl:text><xsl:value-of
      select="@srcfile" /></xsl:variable>
    <xsl:variable name="o"><xsl:text>-o../html/</xsl:text><xsl:value-of select="@srcfile" /><xsl:value-of
      select="@dstext"/></xsl:variable>
    <arg line="{$Classpath}" />
    <arg line ="{'org.vishia.xml.Textfile2Html'}" />
	  <arg line="{$i}" />
	  <arg line="{$o}" />
  </exec>
  -->
</xsl:template>





<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="genXmiFromHeaderTarget">
  <echo message="gen XMI from Header" />
  <!-- ZBNFparser-->
  <xsl:for-each select=".//input[boolean(@file)]">
    <xsl:variable
      name="filepath"><xsl:text>(?!../param[@name='srcpath']/@value?)(?@path?)(?@file?).h</xsl:text></xsl:variable>
    <xsl:variable name="msg"><xsl:text>parsing with Sbnf2Xml/Cheader.sbnf: (?$filepath?)</xsl:text></xsl:variable>
    <echo message="{$msg}" /> 
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$Classpath}" />
      <arg line ="org.vishia.zbnfXml.Zbnf2Xml" />
      <xsl:variable name="i"><xsl:text>-i(?$filepath?)</xsl:text></xsl:variable>
      <arg line="{$i}" />
      <arg line="{'-s${env.XML_TOOLBASE}/Sbnf2Xml/Cheader.sbnf'}" />
      <xsl:variable name="o"><xsl:text>-y${tmp}/(?@file?).zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$o}" />
      <arg line="{'--report:${tmp}/zbnf.rpt --rlevel:334'}" />
    </exec>
  </xsl:for-each>
  <!-- generate .types.xml -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="org.vishia.xml.Xslt" />
    <xsl:for-each select="input">
      <xsl:variable name="i"><xsl:text>-i${tmp}/(?@file?).zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$i}" />
    </xsl:for-each>  
    <arg line="{'-t${env.XML_TOOLBASE}/XmlDocu_xsl/HeaderXmlDissolveTypes.xsl'}" />
    <arg line="-w+" />
    <xsl:variable name="o"><xsl:text>-y${tmp}/(?!output/@file?).types.xml</xsl:text></xsl:variable>
    <arg line="{$o}" />
  </exec>
  <!-- generate XMI -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="org.vishia.xml.Xslt" />
    <xsl:for-each select=".//input[boolean(@file)]">
      <xsl:variable name="i"><xsl:text>-i${tmp}/(?@file?).zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$i}" />
    </xsl:for-each>  
    <xsl:variable name="iTypes"><xsl:text>-i${tmp}/(?!output/@file?).types.xml</xsl:text></xsl:variable>
    <arg line="{$iTypes}" />
    <arg line="{'-t${env.XML_TOOLBASE}/XmlDocu_xsl/HeaderXml2Xmi.xsl'}" />
    <arg line="-w+" />
    <xsl:variable name="y"><xsl:text>-y(?!output/@file?)(?!output/@ext?)</xsl:text></xsl:variable>
    <arg line="{$y}" />
  </exec>
</xsl:template>


  
<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="genXmiFromHeader2">
  <echo message="gen XMI from Header" />
  <!-- ZBNFparser-->
  <xsl:for-each select=".//input[boolean(@file)]">
    <xsl:variable
      name="filepath"><xsl:text>(?!../param[@name='srcpath']/@value?)(?@path?)(?@file?).h</xsl:text></xsl:variable>
    <xsl:variable name="msg"><xsl:text>parsing with Sbnf2Xml/Cheader.sbnf: (?$filepath?)</xsl:text></xsl:variable>
    <echo message="{$msg}" /> 
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$Classpath}" />
      <arg line ="org.vishia.zbnfXml.Zbnf2Xml" />
      <xsl:variable name="i"><xsl:text>-i(?$filepath?)</xsl:text></xsl:variable>
      <arg line="{$i}" />
      <arg line="{'-s${env.XML_TOOLBASE}/Sbnf2Xml/Cheader.sbnf'}" />
      <xsl:variable name="o"><xsl:text>-y${tmp}/(?@file?).zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$o}" />
      <arg line="{'--report:${tmp}/zbnf.rpt --rlevel:334'}" />
    </exec>
  </xsl:for-each>
  <!-- generate .types.xml -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="org.vishia.xml.Xslt" />
    <xsl:for-each select="input">
      <xsl:variable name="i"><xsl:text>-i${tmp}/(?@file?).zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$i}" />
    </xsl:for-each>  
    <arg line="{'-t${env.XML_TOOLBASE}/xsl/CheaderTypes.xsl'}" />
    <arg line="-w+" />
    <xsl:variable name="o"><xsl:text>-y${tmp}/(?!output/@file?).types.xml</xsl:text></xsl:variable>
    <arg line="{$o}" />
  </exec>
  <!-- xsltpre -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$Classpath}" />
    <arg line ="org.vishia.xml.Xsltpre" />
    <arg line="{'-i${env.XML_TOOLBASE}/xsl/Cheader2Xmi.xslp'}" />
    <arg line="{'-o${env.XML_TOOLBASE}/xsl/gen/Cheader2Xmi.xsl'}" />
  </exec>
  <!-- generate XMI -->
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="org.vishia.xml.Xslt" />
    <xsl:for-each select=".//input[boolean(@file)]">
      <xsl:variable name="i"><xsl:text>-i${tmp}/(?@file?).zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$i}" />
    </xsl:for-each>  
    <xsl:variable name="iTypes"><xsl:text>-i${tmp}/(?!output/@file?).types.xml</xsl:text></xsl:variable>
    <arg line="{$iTypes}" />
    <arg line="{'-t${env.XML_TOOLBASE}/xsl/gen/Cheader2Xmi.xsl'}" />
    <arg line="-w+" />
    <xsl:variable name="y"><xsl:text>-y(?!output/@file?)(?!output/@ext?)</xsl:text></xsl:variable>
    <arg line="{$y}" />
  </exec>
</xsl:template>


  
<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="genReflection">
<xsl:param name="targetfile" />
  <xsl:variable name="targetfile_h"><xsl:for-each select="output">
    <xsl:call-template name="pathbase" /><xsl:value-of select="@path" /><xsl:value-of select="@file"
      /><xsl:text>.h</xsl:text>
  </xsl:for-each></xsl:variable>
  <echo message="genReflection from XMI" />
  <xsl:choose><xsl:when test="input[1]/@ext = '.xmi'" >
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$Classpath}" />
      <arg line ="org.vishia.xml.Xsltpre" />
      <arg line="{'-i${env.XML_TOOLBASE}/XmlDocu_xsl/Xmi2Reflection.xslp'}" />
      <arg line="{'-o${env.XML_TOOLBASE}/XmlDocu_xsl/gen/Xmi2Reflection.xsl'}" />
    </exec>
    <echo message="chmod??{$targetfile}??" />
    <chmod file="{$targetfile}" perm="777"/><!-- make it writeable if it is read only -->
    <chmod file="{$targetfile_h}" perm="777"/><!-- chmod does not work probably??? -->
    <delete file="{$targetfile}" /><!-- delete versus chmod?  -->
    <delete file="{$targetfile_h}" />
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$ClasspathSaxon}" />
      <arg line ="net.sf.saxon.Transform" />
      <xsl:variable name="s"><xsl:text>-s
        (?!input/@path?)(?!input[1]/@file?)(?!input[1]/@ext?)</xsl:text></xsl:variable>
      <arg line="{$s}" />
      <arg line="{'${env.XML_TOOLBASE}/XmlDocu_xsl/gen/Xmi2Reflection.xsl'}" />
      <xsl:variable name="UmlComponent">
        <xsl:choose><xsl:when test="param[@name='component']"><xsl:value-of select="param[@name='component']/@value" />
        </xsl:when><xsl:otherwise><xsl:text>header</xsl:text>
        </xsl:otherwise></xsl:choose>
      </xsl:variable>
      <arg line="{'UmlComponent='}{$UmlComponent}" /><!-- see Xmi2Reflection: UML component from which the scope is
        taken. -->
      <!-- xsl:variable name="UmlComponent"><xsl:text>ReflectionName="VFN"
        UmlComponent="Header"</xsl:text></xsl:variable -->
      <xsl:if test="param[@name='name']">
        <!-- see Xmi2reflection, name of the C-struct for reflection. Default is UmlComponent as name --> 
        <arg line="{'ReflectionName='}{param[@name='name']/@value}" />
      </xsl:if>  
      <xsl:variable name="Outputfile"><xsl:text>Outputfile="(?!output/@file?)"</xsl:text></xsl:variable>
      <arg line="{$Outputfile}" />
    </exec>
  </xsl:when><xsl:otherwise>
    <echo message="genReflection, input extension have to be .xmi" />
  </xsl:otherwise></xsl:choose>
</xsl:template>



<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="CHeader2JavaByteCoding">
  <!-- ZbnfParser-->
  <xsl:for-each select=".//input[boolean(@file)]">
    <xsl:variable
      name="filepath"><xsl:text>(?!../param[@name='srcpath']/@value?)(?@path?)(?@file?).h</xsl:text></xsl:variable>
    <xsl:variable name="msg"><xsl:text>gen CHeader2JavaByteCoding: parsing (?$filepath?)</xsl:text></xsl:variable>
    <echo message="{$msg}" /> 
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$Classpath}" />
      <arg line ="org.vishia.zbnfXml.Zbnf2Xml" />
      <xsl:variable name="i"><xsl:text>-i(?$filepath?)</xsl:text></xsl:variable>
      <arg line="{$i}" />
      <arg line="{'-s${env.XML_TOOLBASE}/Sbnf2Xml/Cheader.sbnf'}" />
      <xsl:variable name="o"><xsl:text>-y${tmp}/(?@file?).zbnf.xml</xsl:text></xsl:variable>
      <arg line="{$o}" />
      <xsl:variable name="report"><xsl:text>--report:${tmp}/(?@file?).zbnf.rpt --rlevel:335</xsl:text></xsl:variable>
      <arg line="{$report }" />
    </exec>
  </xsl:for-each>
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$Classpath}" />
    <arg line ="org.vishia.xml.Xsltpre" />
    <arg line="-i{'${env.XML_TOOLBASE}'}/xsl/CHeader2ByteDataAccess_Java.xslp" />
    <arg line="-o{'${env.XML_TOOLBASE}'}/xsl/gen/CHeader2ByteDataAccess_Java.xsl" />
  </exec>
  <xsl:variable name="outPathFile"><xsl:text>(?!output/@pathbase?)(?if
    "output/@pathbase"?)/(?/if?)(?!output/@path?)(?!output/@file?)(?!output/@ext?)</xsl:text></xsl:variable>
  <delete file="{$outPathFile}" />
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$ClasspathSaxon}" />
    <arg line ="net.sf.saxon.Transform" />

    <xsl:variable name="s"><xsl:text>-s ${tmp}/(?!input[1]/@file?).zbnf.xml</xsl:text></xsl:variable>
    <arg line="{$s}" />

    <xsl:variable name="o"><xsl:text>-o (?$outPathFile?)</xsl:text></xsl:variable>
    <arg line="{$o}" />

    <arg line="{'${env.XML_TOOLBASE}/xsl/gen/CHeader2ByteDataAccess_Java.xsl'}" />

    <xsl:variable
      name="outPackageArg"><xsl:text>outPackage="(?!translate(substring(output/@path,1,string-length(output/@path)-1),
      '/','.')?)"</xsl:text></xsl:variable>
    <arg line="{$outPackageArg}" />

    <xsl:variable name="outFile"><xsl:text>outFile="(?!output/@file?)"</xsl:text></xsl:variable>
    <arg line="{$outFile}" />
  </exec>
</xsl:template>


  
<xsl:template name="copyNewerFiles">
  <xsl:call-template name="copyFiles">
    <xsl:with-param name="mode" select="'+newer+replace+'" />
  </xsl:call-template>
</xsl:template>

<xsl:template name="copyChangedFiles">
  <xsl:call-template name="copyFiles">
    <xsl:with-param name="mode" select="'+newer+replace+'" />
    <xsl:with-param name="testContent" select="'bytewise'" />
  </xsl:call-template>
</xsl:template>



<xsl:template name="copyFiles">
<xsl:param name="mode" select="'+everytime+replace+'" />
<xsl:param name="testContent"/>
  <xsl:variable name="targetName"><xsl:call-template name="targetName" /></xsl:variable>
  <xsl:variable name="outputPath">
    <xsl:for-each select="output">
      <xsl:call-template name="pathbase" />
      <xsl:value-of select="@path" />
      <xsl:value-of select="@file" /><!-- if no attribute file, it is empty but replaced by input/@file-->
      <xsl:value-of select="@ext" /><!-- if no attribute ext, it is empty but replaced by input/@ext -->
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="copyCmd">
    <xsl:choose><xsl:when test="string-length($testContent) gt 0">
      <xsl:text>Zcopy</xsl:text>
    </xsl:when><xsl:otherwise>
      <xsl:text>copy</xsl:text>
    </xsl:otherwise></xsl:choose>
  </xsl:variable>  
  <target name="{$targetName}">
    <!-- this target contains some copy tasks, every copy tests the uptodate inside. -->
    <xsl:variable name="mode1">
      <xsl:value-of select="$mode" />
      <xsl:if test="output/@allTree"><xsl:text>+toDir+</xsl:text></xsl:if>
      <xsl:if test="output/@someFiles"><xsl:text>+toInputFile+</xsl:text></xsl:if>
      <xsl:if test="output/@ext='.*'"><xsl:text>+toInputExt+</xsl:text></xsl:if>
    </xsl:variable>
    <xsl:call-template name="evaluateInput">
      <xsl:with-param name="call" select="'copyFiles-exec'" />
      <xsl:with-param name="p1" select="$mode1" />
      <xsl:with-param name="p2" select="$outputPath" />
      <xsl:with-param name="p3" select="output" />
      <xsl:with-param name="p4" select="$copyCmd" />
      <xsl:with-param name="p5" select="$testContent" />
    </xsl:call-template>
  </target>
</xsl:template>

<xsl:template name="copyFiles-exec"><!-- the template called inside evaluateInput -->
<xsl:param name="pathbase" /><!-- built in evaluateInput for the inputfile -->  
<xsl:param name="p1" /><!-- mode -->
<xsl:param name="p2" /><!-- outputPath -->
<xsl:param name="p3" /><!-- xmlOutput -->
<xsl:param name="p4" /><!-- copyCmd copy or Zcopy -->
<xsl:param name="p5" /><!-- testContent -->
  <!-- copy -->
  <xsl:element name="{$p4}" >
    <!-- dst: tofile or todir: -->
    <xsl:choose><xsl:when test="contains($p1,'+toDir+')" ><!-- xsl:when test="@allTree" -->
      <xsl:attribute name="todir"><xsl:text>(?$p2?)</xsl:text></xsl:attribute>
    </xsl:when><xsl:otherwise>
      <xsl:attribute name="tofile" >
        <xsl:value-of select="$p2"/>
        <xsl:choose><xsl:when test="boolean($p3/@allTree) and not($p3/@ext)">
          <!-- use the local path/file.ext from input but the extension from output-->
          <xsl:text>(?@path?)(?@file?)(?if "@someFiles"?)*(?/if?)(?@ext?)</xsl:text>
        </xsl:when><xsl:when test="boolean($p3/@allTree)">
          <xsl:call-template name="localPathfile" /><!-- use local path/file.ext from input. -->
        </xsl:when><xsl:otherwise>
          <!-- the $outputPath contains always file.ext, its all ready. --> 
        </xsl:otherwise></xsl:choose>
      </xsl:attribute>
    </xsl:otherwise></xsl:choose>
    <!-- -->  
    <!-- src: -->  
    <xsl:variable name="dir"><xsl:text>(?$pathbase?)</xsl:text></xsl:variable>
    <xsl:variable name="file">
      <xsl:choose><xsl:when test="boolean(@allTree) and false() and (boolean(@file) or boolean(@ext))">
      </xsl:when><xsl:when test="boolean(@allTree)">
        <!-- allTree -->
          <xsl:if test="true() or boolean(@file) or boolean(@ext)">
            <xsl:text>(?@path?)**/(?@file?)*(?@ext?)</xsl:text>
          </xsl:if>  
        <!-- -->
        <!-- /allTree -->
      </xsl:when><xsl:otherwise>
        <!-- use extension from input --> 
        <xsl:text>(?call localPathfile()?)</xsl:text>
      </xsl:otherwise></xsl:choose>
    </xsl:variable>
    <!-- -->
    <!-- consideres different argument syntax between copy and Zcopy: -->
    <xsl:choose><xsl:when test="$p4='copy'">
      <fileset dir="{$dir}">
        <include name="{$file}" />
      </fileset>
    </xsl:when><xsl:otherwise>
      <xsl:attribute name="dir"><xsl:value-of select="$dir" /></xsl:attribute>
      <xsl:attribute name="file"><xsl:value-of select="$file" /></xsl:attribute>
    </xsl:otherwise></xsl:choose>    
    <!-- -->
  </xsl:element> 
</xsl:template>




<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="zipFiles">
  <xsl:variable name="zipdir"><xsl:for-each select="output"><xsl:call-template name="pathbase" /><xsl:value-of
    select="@path" /></xsl:for-each></xsl:variable>
  <xsl:variable name="zipfile"><xsl:for-each select="output"><xsl:call-template name="absPathfile"
    /></xsl:for-each></xsl:variable>
  <mkdir dir="{$zipdir}" />
  <chmod file="{$zipfile}" perm="777"/>
  <delete file="{$zipfile}" />
  <zip destfile="{$zipfile}">
    <xsl:for-each select=".//input">
      <xsl:variable name="pathbase"><xsl:call-template name="pathbase" /></xsl:variable>
      
      <xsl:choose><xsl:when test="boolean(@allTree) and boolean(@pathbase)">
        <fileset dir="{$pathbase}" includes="{@path}**/*.*" />
      </xsl:when><xsl:when test="boolean(@allTree)">
        <fileset dir="{$pathbase}{@path}" />
      </xsl:when><xsl:when test="boolean(@pathbase)">
        <fileset dir="{$pathbase}" includes="{@path}{@file}{@ext}" />
      </xsl:when><xsl:otherwise>
        <fileset file="{$pathbase}{@path}{@file}{@ext}" />
      </xsl:otherwise></xsl:choose>
      
    </xsl:for-each>    
  </zip>
</xsl:template>




<!-- This template translates a Zmake-expression like
  
       tmp/*.zbnf.xml := zbnfCheader($Headerfiles);
  
     in some targets to translate the individually files from c-header via Cheader.zbnf in xml.
     a common target is build with the depends of all some zbnf-translating targets.
 -->
  <xsl:template name="zbnfCheader">
  <xsl:call-template name="genTargetForEachInput">
    <xsl:with-param name="genExecForEachInput" select="'exec_Zbnf2Xml_Cheader'" />
    <xsl:with-param name="xmlTool_srcFiles" >
      <srcfiles file="{'${env.XML_TOOLBASE}/Sbnf2Xml/Cheader.sbnf'}" />
    </xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template name="exec_Zbnf2Xml_Cheader">
<xsl:param name="targetfile" />  
<xsl:param name="srcfile" />
<xsl:param name="xmlInputNode" />
<xsl:param name="xmlTargetNode" />
  <!-- the srcfile without extension .h -->
  <echo message="{'Zbnf2Xml-Cheader.zbnf: '}{$targetfile}" />
  <exec dir="{$curDir}" executable= "java" failonerror="true">
    <arg line="{$Classpath}" />
    <arg line ="org.vishia.zbnfXml.Zbnf2Xml" />
    <arg line="{'-i:'}{$srcfile}" />
    <arg line="{'-s:${env.XML_TOOLBASE}/Sbnf2Xml/Cheader.sbnf'}" />
    <arg line="{'-y:'}{$targetfile}" />
    <xsl:variable
      name="file"><xsl:text>-a:@filename="(?$xmlInputNode/@path?)(?$xmlInputNode/@file?)"</xsl:text></xsl:variable>
    <arg line="{$file}" />
  </exec>
</xsl:template>







<!-- This template translates a Zmake-expression like
  
     MyOutput.xmi := genXmiFromZbnfCheader($Headerfiles);
  
     in a targets to translate the zbnf.xml-Headerfiles to one XMI-File.
     It is assumed that targets to parse the Headerfiles and convert to *.zbnf.xml are always exist.
     Use the Zmake operation zbnfCheader therefore.  
 --> 
<xsl:template name="genXmiFromZbnfCheader">
  <xsl:variable name="targetName"><xsl:call-template name="targetName" /></xsl:variable>
  <xsl:variable name="targetUptodate"><xsl:value-of select="$targetName" />_isUptodate</xsl:variable>
  <xsl:variable name="types_xml"><xsl:text>${tmp}/(?!output/@file?).types.xml</xsl:text></xsl:variable>
  <xsl:variable name="targetfile"><xsl:text>(?call absPathfile:"output"()?)</xsl:text></xsl:variable>
  <xsl:if test="not(param[@name='zbnfCheaderTarget'])">
    <xsl:message terminate="yes"><xsl:text>
ABORT: The zmake routine 'genXmiFromZbnfCheader()' must have a argument 'zbnfCheaderTarget="target"'.
This argument have to be refer the target responsible for making the xml files from Header via parsing with
  Cheader.zbnf.
      </xsl:text>
    </xsl:message>
  </xsl:if>
  <target name="{$targetName}" description="generate from Zmake-routine: genXmiFromZbnfCheader"
    unless="{$targetUptodate}">
    <xsl:variable name="depends">
      <xsl:call-template name="evaluateInput">
        <xsl:with-param name="call" select="'genDependsToTarget-dependsInput'" />
        <xsl:with-param name="p1" select="param[@name='zbnfCheaderTarget']/@value" />
        <xsl:with-param name="p2" select="''" />
        <xsl:with-param name="p3" select="''" />
        <xsl:with-param name="p4" select="''" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:attribute name="depends"><xsl:text>(?$depends?)(?$targetUptodate?)</xsl:text></xsl:attribute>
    <echo message="{'Xslt-CheaderTypes.xsl: '}{$types_xml}" />
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$ClasspathSaxon}" />
      <arg line ="org.vishia.xml.Xslt" />
      <xsl:call-template name="evaluateInput">
        <xsl:with-param name="call" select="'evaluateInput_XsltPathExt'" />
        <xsl:with-param name="p1" select="'${tmp}/'" />
        <xsl:with-param name="p2" select="'.zbnf.xml'" />
      </xsl:call-template>
      <!-- arg line="{'-t${env.XML_TOOLBASE}/xsl/CheaderTypes.xsl'}" / -->
      <arg line="{'-t${env.XML_TOOLBASE}/XmlDocu_xsl/HeaderXmlDissolveTypes.xsl'}" />
      <arg line="-w+" />
      <xsl:variable name="o"><xsl:text>-y${tmp}/(?!output/@file?).types.xml</xsl:text></xsl:variable>
      <arg line="{$o}" />
    </exec>
    <exec dir="{$curDir}" executable= "java" failonerror="true">
      <arg line="{$ClasspathSaxon}" />
      <arg line ="org.vishia.xml.Xslt" />
      <xsl:call-template name="evaluateInput">
        <xsl:with-param name="call" select="'evaluateInput_XsltPathExt'" />
        <xsl:with-param name="p1" select="'${tmp}/'" />
        <xsl:with-param name="p2" select="'.zbnf.xml'" />
      </xsl:call-template>
      <xsl:variable name="iTypes"><xsl:text>-i${tmp}/(?!output/@file?).types.xml</xsl:text></xsl:variable>
      <arg line="{$iTypes}" />
      <arg line="{'-t${env.XML_TOOLBASE}/XmlDocu_xsl/HeaderXml2Xmi.xsl'}" />
      <arg line="-w+" />
      <arg line="{'-y'}{$targetfile}" />
    </exec>
  </target>
  <target name="{$targetUptodate}">
    <uptodate property="{$targetUptodate}" targetfile="{$targetfile}">
      <xsl:call-template name="evaluateInput">
        <xsl:with-param name="call" select="'uptodateSource'" />
      </xsl:call-template>
      <srcfiles file="{'${env.XML_TOOLBASE}/xsl/CheaderTypes.xsl'}" />
      <srcfiles file="{'${env.XML_TOOLBASE}/XslTRA/antmake_rpy.xslp'}" />
    </uptodate> 
  </target>
</xsl:template>






<!-- ***********************************************************************************************************
     ***********************************************************************************************************
     ***********************************************************************************************************
     commonly useable routines:
 -->    


  
<xsl:template name="targetName">
  <xsl:choose><xsl:when test="param[@name='target']">
    <xsl:value-of select="param[@name='target']/@value" /> 
  </xsl:when><xsl:when test="param[@name='task']">
    <xsl:value-of select="param[@name='task']/@value" /> 
  </xsl:when><xsl:otherwise>
    <xsl:variable
      name="targetNameRaw"><xsl:text>(?!output/@path?)(?!output/@file?)(?!output/@ext?)</xsl:text></xsl:variable>
    <xsl:value-of select="translate($targetNameRaw, '/\:', '/\:')" />
  </xsl:otherwise></xsl:choose>
</xsl:template>





<!-- This template is commonly useable to translate all input files with the same given algorithmus
     in some targets.
     a common target is build with the depends of all some zbnf-translating targets.
 -->
<xsl:template name="genTargetForEachInput">
<xsl:param name="genExecForEachInput" /><!-- name of the generateExec-Routine. -->
<xsl:param name="xmlTool_srcFiles" /><!-- contains some <srcfiles ...> elements there are additinal to consider --> 
  <xsl:variable name="targetName"><xsl:call-template name="targetName" /></xsl:variable>
  <xsl:variable name="outputPre"><xsl:for-each select="output"><xsl:call-template name="pathPre"
    /></xsl:for-each></xsl:variable>
  <xsl:variable name="outputPost"><xsl:for-each select="output"><xsl:call-template name="pathPost"
    /></xsl:for-each></xsl:variable>
  <xsl:call-template name="evaluateInput">
    <xsl:with-param name="call" select="'genTargetForInput'" />
    <xsl:with-param name="p1" select="$targetName" /><!-- base for the some targets names -->
    <xsl:with-param name="p2" select="$outputPre" />
    <xsl:with-param name="p3" select="$outputPost" />
    <xsl:with-param name="p4" select="$genExecForEachInput" />
    <xsl:with-param name="p5" select="." /><!-- xmlTargetNode -->
    <xsl:with-param name="p6" select="$xmlTool_srcFiles" />
  </xsl:call-template>
  <xsl:text>
    <!-- xxx -->
  </xsl:text>
  <xsl:variable name="targetUptodate"><xsl:value-of select="$targetName" />_isUptodate</xsl:variable>
  <xsl:variable name="targetfile"><xsl:text>(?call absPathfile:"output"()?)</xsl:text></xsl:variable>
  <!-- xxx -->
  <target name="{$targetName}" 
    description="{'generate from genTargetForEachInput: '}{$genExecForEachInput}" 
    unless="{$targetUptodate}">
    <xsl:variable name="depends">
      <xsl:call-template name="evaluateInput">
        <xsl:with-param name="call" select="'genDependsToTarget-dependsInput'" />
        <xsl:with-param name="p1" select="$targetName" /><!-- base for the some targets names -->
      </xsl:call-template>
    </xsl:variable>
    <xsl:attribute name="depends"><xsl:text>(?$depends?)(?$targetUptodate?)</xsl:text></xsl:attribute>
  </target>
  <!-- xxx -->
  <target name="{$targetUptodate}">
    <uptodate property="{$targetUptodate}" targetfile="{$targetfile}">
      <xsl:call-template name="evaluateInput">
        <xsl:with-param name="call" select="'uptodateSource'" />
      </xsl:call-template>
      <xsl:copy-of select="$xmlTool_srcFiles" />
    </uptodate> 
  </target>
  <!-- xxx -->
</xsl:template>

<!-- This template is called inside genTargetForEachInput for each input -->  
<xsl:template name="genTargetForInput">
<xsl:param name="p1" /><!-- name of the superior target as basename -->
<xsl:param name="p2" /><!-- pre-part to build the targetfile name with input file path/name.ext -->
<xsl:param name="p3" /><!-- post-part,the targetfile name is built with p2+inputfilfile.ext+p3 -->
<xsl:param name="p4" /><!-- name of the template to generate the ant.xml-code for the exec routine -->
<xsl:param name="p5" /><!-- The xml target node of the Zmake Routine to get parameters -->
<xsl:param name="p6" /><!-- additional uptodate src $xmlTool_srcFiles -->
  <xsl:variable name="targetName"><xsl:text>(?$p1?):(?@path?)(?@file?)(?@ext?)</xsl:text></xsl:variable>
  <xsl:variable name="targetUptodate"><xsl:value-of select="$targetName" />_isUptodate</xsl:variable>
  <xsl:variable name="targetfile"><xsl:text>(?$p2?)(?@path?)(?@file?)(?@ext?)(?$p3?)</xsl:text></xsl:variable>
  <xsl:variable name="srcfile"><xsl:call-template name="absPathfile" /></xsl:variable>
  <xsl:variable name="description"><xsl:text>generate from ZmakeStd.xslp: genTargetForInput:(?$p4?),
    input:(?@path?)(?@file?)(?@ext?)</xsl:text></xsl:variable>
  <target name="{$targetName}" 
    description="{$description} " 
    depends="{$targetUptodate}" unless="{$targetUptodate}">
    <saxon:call-template name="{$p4}">
      <xsl:with-param name="srcfile" select="$srcfile" />
      <xsl:with-param name="targetfile" select="$targetfile" />
      <xsl:with-param name="xmlInputNode" select="." />
      <xsl:with-param name="xmlTargetNode" select="$p5" />
    </saxon:call-template>
  </target>
  <target name="{$targetUptodate}">
    <uptodate property="{$targetUptodate}" targetfile="{$targetfile}">
      <srcfiles file="{$srcfile}" />
      <xsl:copy-of select="$p6" />
    </uptodate> 
  </target>
  <xsl:text>
    
    
  </xsl:text>
</xsl:template>  









<!-- This template is commonly useable to translate all input files with the same given algorithmus
     in some targets.
     a common target is build with the depends of all some zbnf-translating targets.
 -->
<xsl:template name="genTargetWithAvaileableTestFirstInput_UptodateAllInput">
<xsl:param name="genExec" /><!-- name of the generateExec-Routine. -->
<xsl:param name="xmlTool_srcFiles" /><!-- contains some <srcfiles ...> elements there are additinal to consider --> 
<xsl:param name="targetfile" />  
  <xsl:variable name="targetName"><xsl:call-template name="targetName" /></xsl:variable>
  <xsl:variable name="isUptodate"><xsl:text>isUptodate:</xsl:text><xsl:value-of select="$targetName" /></xsl:variable>
  <xsl:variable name="isAvailable"><xsl:text>isAvailable:</xsl:text><xsl:value-of select="$targetName" /></xsl:variable>
  <xsl:variable name="firstInput"><xsl:for-each select="input[1]"><xsl:call-template name="absPathfile"
    /></xsl:for-each><!-- xsl:text>(?!output/@path?)(?!output/@file?)(?!output/@ext?)</xsl:text --></xsl:variable>
  <target name="{$targetName}" depends="{$isAvailable}" if="{$isAvailable}" >
    <antcall target="exec:{$targetName}" />
  </target>
  <target name="exec:{$targetName}" depends="{$isUptodate}" unless="{$isUptodate}" >
    <saxon:call-template name="{$genExec}">
      <xsl:with-param name="targetfile" select="$targetfile" />
    </saxon:call-template>
  </target>
  <target name="{$isUptodate}" >
    <uptodate property="{$isUptodate}" targetfile="{$targetfile}">
      <xsl:call-template name="evaluateInput">
        <xsl:with-param name="call" select="'uptodateSource'" />
      </xsl:call-template>
    </uptodate> 
  </target>
  <target name="{$isAvailable}" >
    <available property="{$isAvailable}" file="{$firstInput}" />
  </target>
</xsl:template>





  <!-- This template generates the input arg for org.vishia.xml.Xslt.
     Acutal xml node is a <file> for input. The template may be used within template name="evaluateInput".  
 --> 
<xsl:template name="evaluateInput_XsltPathExt" >
<xsl:param name="p1" />  
<xsl:param name="p2" />  
  <xsl:variable name="i"><xsl:text>-i(?$p1?)(?@path?)(?@file?)(?@ext?)(?$p2?)</xsl:text></xsl:variable>
  <arg line="{$i}" />
</xsl:template>  


<!-- This template generates a text for depends-attribute with all input files.
     Acutal xml node is a <file> for input. The template may be used within template name="evaluateInput".
     The names of the targets are built with p1 + @path + @file + @ext  
 --> 
<xsl:template name="genDependsToTarget-dependsInput" >
<xsl:param name="p1" /><!-- base name for target -->   
  <xsl:variable name="dependsTarget"><xsl:text>(?$p1?):(?@path?)(?@file?)(?@ext?)</xsl:text></xsl:variable>
  <xsl:text>(?$dependsTarget?), </xsl:text>
</xsl:template>

<!-- This template generates one entry for <update ...> element in <target> with all input files.
     It is useable universally. 
     Acutal xml node is a <file> for input. The template may be used within template name="evaluateInput".  
 --> 
<xsl:template name="uptodateSource" >
  <xsl:variable name="srcfile"><xsl:call-template name="absPathfile" /></xsl:variable>
  <xsl:choose><xsl:when test="@allTree">
    <xsl:variable name="srcpath"><xsl:call-template name="pathbase" /><xsl:value-of select="@path" /></xsl:variable>
    <srcfiles dir="{$srcpath}" includes="**/{@file}*{@ext}" />
  </xsl:when><xsl:otherwise>
    <xsl:variable name="srcfile"><xsl:call-template name="absPathfile" /></xsl:variable>
    <srcfiles file="{$srcfile}" />
  </xsl:otherwise></xsl:choose>
   
</xsl:template>




<!--This template calls the given named template for all input nodes, considering also inputSet.
    It uses the saxon:call-template because the name of the called template is given as param.
    All params to call are named p1...  
 -->  
<xsl:template name="evaluateInput">
<xsl:param name="call" />  
<xsl:param name="p1" />  
<xsl:param name="p2" />  
<xsl:param name="p3" />  
<xsl:param name="p4" />  
<xsl:param name="p5" />  
<xsl:param name="p6" />  
<xsl:param name="p7" />  
<xsl:param name="p8" />  
  <xsl:variable name="srcpath">
    <xsl:text>(?if "not(srcpath/@abspath)"?)${curDir}/(?/if?)(?if "srcpath"?)(?!srcpath/@pathbase?)/(?/if?)</xsl:text>
    <!-- xsl:choose><xsl:when test="param[@name='srcpath']"><xsl:value-of select="param[@name='srcpath']/@value" />
    </xsl:when><xsl:otherwise><xsl:text>${curDir}</xsl:text>
    </xsl:otherwise></xsl:choose-->
  </xsl:variable>
  <xsl:for-each select="input">
    <xsl:variable name="pathbase"><xsl:text>(?call pathbase(srcpath="$srcpath")?)</xsl:text></xsl:variable>
    <saxon:call-template name="{$call}">
      <xsl:with-param name="pathbase" select="$pathbase" />
      <xsl:with-param name="p1" select="$p1" />
      <xsl:with-param name="p2" select="$p2" />
      <xsl:with-param name="p3" select="$p3" />
      <xsl:with-param name="p4" select="$p4" />
      <xsl:with-param name="p5" select="$p5" />
      <xsl:with-param name="p6" select="$p6" />
      <xsl:with-param name="p7" select="$p7" />
      <xsl:with-param name="p8" select="$p8" />
    </saxon:call-template>
  </xsl:for-each>
  <xsl:for-each select="inputSet">
    <xsl:variable name="nameInputSet" select="@name" />
    <xsl:for-each select="/.//variable[@name=$nameInputSet]/fileset/file">
      <xsl:variable name="pathbase"><xsl:call-template name="pathbase" /></xsl:variable>
      <saxon:call-template name="{$call}">
        <xsl:with-param name="pathbase" select="$pathbase" />
        <xsl:with-param name="p1" select="$p1" />
        <xsl:with-param name="p2" select="$p2" />
        <xsl:with-param name="p3" select="$p3" />
        <xsl:with-param name="p4" select="$p4" />
        <xsl:with-param name="p5" select="$p5" />
        <xsl:with-param name="p6" select="$p6" />
        <xsl:with-param name="p7" select="$p7" />
        <xsl:with-param name="p8" select="$p8" />
      </saxon:call-template>
    </xsl:for-each>    
  </xsl:for-each>
</xsl:template>





<xsl:template name="absPathfile">
  <!-- actual xml node is input or output, containing @file @path etc. -->
  <xsl:call-template name="pathbase" /><xsl:call-template name="localPathfile" />
</xsl:template>


<xsl:template name="localPathfile">
  <!-- actual xml node is input or output, containing @file @path etc. -->
  <xsl:value-of select="@path" /><xsl:value-of select="@file" />
  <xsl:if test="@someFiles"><xsl:text>*</xsl:text></xsl:if>
  <xsl:value-of select="@ext" />
</xsl:template>


<xsl:template name="pathfileAllTree">
  <!-- actual xml node is input or output, containing @file @path etc. -->
  <xsl:call-template name="pathbase" /><xsl:value-of select="@path" />
  <xsl:choose><xsl:when test="@allTree"><xsl:text>**/*</xsl:text>
  </xsl:when><xsl:otherwise><xsl:value-of select="@file" /><xsl:value-of select="@ext" />
  </xsl:otherwise></xsl:choose>
</xsl:template>


  <xsl:template name="pathPre">
<!-- actual xml node is input or output, containing @file @path etc. -->
  <xsl:call-template name="pathbase" /><xsl:value-of select="@path" />
</xsl:template>


<xsl:template name="pathPost">
<!-- actual xml node is input or output, containing @file @path etc. -->
  <xsl:value-of select="@file" /><xsl:value-of select="@ext" />
</xsl:template>

<!-- generate the base of path with curDir or not, actual xml node is a file description -->
<xsl:template name="pathbase">
<xsl:param name="srcpath" select="'${curDir}/'" />
<!-- actual xml node is input or output, containing @file @path etc. -->
  <xsl:choose><xsl:when test="boolean(@drive) or boolean(@absPath)" >
    <xsl:value-of select="@drive" /><xsl:if test="@pathbase"><xsl:value-of select="@pathbase" />/</xsl:if>
  </xsl:when><xsl:otherwise>
    <xsl:value-of select="$srcpath" /><xsl:if test="@pathbase"><xsl:value-of select="@pathbase" />/</xsl:if>
  </xsl:otherwise></xsl:choose>  
</xsl:template>




<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="stdMake">
<xsl:param name="targetfile" />  
  <xsl:variable name="makefilePath">
    <xsl:for-each select="input[1]"><xsl:call-template name="pathbase" /><xsl:value-of select="@path" /></xsl:for-each>
  </xsl:variable>
  <echo message="stdMake: {$makefilePath}{input[1]/@file}{input[1]/@ext}" />
  <!-- exec dir="{$makefilePath}" executable="d:\ARS\Framework_7_0\AAXDF\Framework_RC\Share\etc\rmosmake.bat"
    failonerror="true" -->
  <exec dir="{$makefilePath}" executable="make" failonerror="true">
    <arg line="{'-f'}" />
    <arg line="{input[1]/@file}{input[1]/@ext}" />
    <arg line="{'clean all'}" />
  </exec>
</xsl:template>




<!-- Note: the output is embedded in <target  name="{output/@file}" depends="{$isUptodate}" unless="{$isUptodate}"> ...
  </target> --> 
<xsl:template name="msMake">
<xsl:param name="targetfile" />  
  <xsl:variable name="makefilePath">
    <xsl:for-each select="input[1]"><xsl:call-template name="pathbase" /><xsl:value-of select="@path" /></xsl:for-each>
  </xsl:variable>
  <xsl:for-each select="param[@name='delete']">
    <xsl:variable name="deleteDir" ><xsl:text>${curDir}/(?@value?)</xsl:text></xsl:variable>
    <echo message="delete {$deleteDir}" /> 
    <delete dir="{$deleteDir}" />
  </xsl:for-each>
  <echo message="nmake {input[1]/@file}{input[1]/@ext}" />
  <!-- exec dir="{$makefilePath}" executable="d:\ARS\Framework_7_0\AAXDF\Framework_RC\Share\etc\rmosmake.bat"
    failonerror="true" -->
  <exec dir="{$makefilePath}" executable="nmake" failonerror="true">
    <arg line="{'/nologo'}" />
    <arg line="{'/S'}" />
    <arg line="{'/F'}" />
    <arg line="{input[1]/@file}{input[1]/@ext}" />
    <arg line="{'all'}" />
  </exec>
</xsl:template>









</xsl:stylesheet>