<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<project name="xslt-test" basedir="." default="tearDown">

  <import file="../../buildfiletest-base.xml"/>

  <target name="setUp">
    <mkdir dir="${output}" />
  </target>


  <target name="testStyleIsSet">
      <xslt in="data.xml" out="${output}/out.xml"/>
  </target>

  <target name="testTransferParameterSet">
      <property name="value" value="myvalue"/>
      <xslt in="data.xml" out="${output}/out.xml" style="printParams.xsl">
          <param name="set" expression="${value}"/>
      </xslt>
  </target>

  <target name="testTransferParameterEmpty">
      <property name="value" value=""/>
      <xslt in="data.xml" out="${output}/out.xml" style="printParams.xsl">
          <param name="empty" expression="${value}"/>
      </xslt>
  </target>

  <target name="testTransferParameterUnset">
      <xslt in="data.xml" out="${output}/out.xml" style="printParams.xsl">
          <param name="undefined" expression="${value}"/>
      </xslt>
  </target>

  <target name="testTransferParameterUnsetWithIf">
      <xslt in="data.xml" out="${output}/out.xml" style="printParams.xsl">
          <param name="undefined" expression="${value}" if="value" />
      </xslt>
  </target>

  <target name="testDefaultMapper">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${output}" basedir=".">
      <param name="set" expression="${value}"/>
    </xslt>
  </target>

  <target name="testCustomMapper">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${output}" basedir=".">
      <param name="set" expression="${value}"/>
      <mapper type="glob" from="data.*" to="out.*"/>
    </xslt>
  </target>

  <target name="testTypedMapper">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${output}" basedir=".">
      <param name="set" expression="${value}"/>
      <globmapper from="data.*" to="out.*"/>
    </xslt>
  </target>

  <target name="testExplicitFileset">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${output}"
          useImplicitFileset="false" basedir="..">
      <param name="set" expression="${value}"/>
      <fileset dir="."/>
    </xslt>
  </target>

  <target name="testNewerStylesheet">
      <antcall target="copyXsl">
        <param name="xsl.value" value="old-value"/>
      </antcall>
      <xslt in="data.xml" out="${output}/out.xml" style="tmp.xsl"/>

      <antcall target="copyXsl">
        <param name="xsl.value" value="new-value"/>
      </antcall>
      <xslt in="data.xml" out="${output}/out.xml" style="tmp.xsl"/>
      <delete file="tmp.xsl"/>
  </target>

  <target name="testDirectoryHierarchyWithDirMatching">
    <mkdir dir="${output}/src/level1/"/>
    <copy file="data.xml" todir="${output}/src/level1/"/>
    <xslt basedir="${output}/src" destdir="${output}/dest"
           style="printParams.xsl"/>
  </target>

  <target name="testDirsWithSpaces">
    <mkdir dir="${output}/s rc/"/>
    <copy file="data.xml" todir="${output}/s rc/"/>
    <xslt basedir="${output}/s rc" destdir="${output}/d est"
           style="printParams.xsl"/>
  </target>

  <target name="copyXsl" if="xsl.value">
      <copy file="testNewerStylesheet.xsl" tofile="tmp.xsl" overwrite="true">
          <filterchain><expandproperties/></filterchain>
      </copy>
  </target>

  <target name="testWithStyleAttrAndResource">
      <!-- also testing style as resources, with refid -->
      <file id="xslFile" file="printParams.xsl"/>
      <xslt in="data.xml" out="${output}/out.xml" style="printParams.xsl">
        <style refid="xslFile" />
      </xslt>
  </target>

  <target name="testWithFileResource">
      <xslt in="data.xml" out="${output}/out.xml">
          <style>
              <file file="printParams.xsl"/>
          </style>
          <param name="set" expression="value"/>
      </xslt>
  </target>

  <target name="testWithUrlResource">
      <makeurl file="printParams.xsl" property="printParams.xsl.url"/>
      <xslt in="data.xml" out="${output}/out.xml">
          <style>
              <url url="${printParams.xsl.url}"/>
          </style>
          <param name="set" expression="value"/>
      </xslt>
  </target>

  <target name="testFilenameAndFiledirAsParam">
      <mkdir dir="${output}/xml/dir"/>
      <copy file="data.xml" tofile="${output}/xml/one.xml"/>
      <copy file="data.xml" tofile="${output}/xml/two.xml"/>
      <copy file="data.xml" tofile="${output}/xml/three.xml"/>
      <copy file="data.xml" tofile="${output}/xml/dir/four.xml"/>
      <xslt style="printFilename.xsl"
            destdir="${output}"
            basedir="${output}/xml"
            includes="**/*.xml"
            extension=".txt"

            filenameparameter="filename"
            filedirparameter="filedir"
      />
  </target>

  <target name="testFilenameAsParam">
      <mkdir dir="${output}/xml/dir"/>
      <copy file="data.xml" tofile="${output}/xml/one.xml"/>
      <copy file="data.xml" tofile="${output}/xml/two.xml"/>
      <copy file="data.xml" tofile="${output}/xml/three.xml"/>
      <copy file="data.xml" tofile="${output}/xml/dir/four.xml"/>
      <xslt style="printFilename.xsl"
            destdir="${output}"
            basedir="${output}/xml"
            includes="**/*.xml"
            extension=".txt"

            filenameparameter="filename"
      />
  </target>

  <target name="testFilenameAsParamNoSetting">
      <mkdir dir="${output}/xml/dir"/>
      <copy file="data.xml" tofile="${output}/xml/one.xml"/>
      <copy file="data.xml" tofile="${output}/xml/two.xml"/>
      <copy file="data.xml" tofile="${output}/xml/three.xml"/>
      <copy file="data.xml" tofile="${output}/xml/dir/four.xml"/>
      <xslt style="printFilename.xsl"
            destdir="${output}"
            basedir="${output}/xml"
            includes="**/*.xml"
            extension=".txt"
      /> <!-- without 'filenameparameter' to check, that the xsl:param is NOT set -->
  </target>

</project>
