xslttest

Perform "Tennison tests".

The task allows you to call the tennison-test templates from within Ant, reporting the results as HTML and failing the build if any fail.

The task works only with Saxon and has been tested with saxon-8.7 but may work earlier versions.

To use the Schema Aware version of Saxon (Saxon SA), you will need JAXP 1.3 classes if you're using Java 1.4 (Java 5.0 users already has it). Download from https://jaxp.dev.java.net/servlets/ProjectDocumentList, extract the archive and add jaxp-api.jar and dom.jar to %ANT_HOME%\lib.

The task is part of the Tennison Tests (XSLT Unit Testing) project (http://tennison-tests.sourceforge.net/) and utlises the set oftemplates therein. You must therefore store the templates in a folder before using this task. For convenience, these are included in the task's JAR file (under main/src/xslt).

There are also some sample templates in the JAR (under main/test/xslt).

A later version of the task may be able to load them directly from the archive, but for now, they must be extracted and located externally (however, this does allow you to modify the templates easily, for example changing the report css).

To use, addthe following to your Ant script.

<taskdef name="xslttest" classname="com.jenitennison.xslt.unittest.XSLTTest"
	classpath="ant-xslttest-v1.0.0.jar" />

SNAPSHOT in the JAR file name would indicatea snapshot versionrelease, not necessarily the latest or formal release. The task is available from the project's home page and is under the GNU LGPL lisense. Its fairly new so feel free to contribute.

Parameters

AttributeDescriptionRequired
srcthe location of the tennison tests; you need to download these and put them hereYes
targetthe output location.Yes
generategenerate the TEST- file. Skips the generate step if false. If false, the TEST- file

must bepre-generated
No (default to true)
licensefolderthe folder where the saxon-license file exists if using Saxon SANo (uses default)

Parameters specified as nested elements

fileset

The fileset containing the XSLT unit tests, see Jeni Tennison's original pages for instructions on how to write tests.

since Ant 1.6.5.

factory

Used to specify factory settings.

Parameters

AttributeDescriptionRequired
namefully qualified classname of the transformer factory to use (must be TraX compliant). For example
  • net.sf.saxon.TransformerFactoryImpl

  • com.saxonica.SchemaAwareTransformerFactory

  • org.apache.xalan.processor.TransformerFactoryImpl

  • org.apache.xalan.xsltc.trax.TransformerFactoryImpl

  • net.sf.saxon.TransformerFactoryImpl

Yes

attribute

Used to specify settings of the processor factory. The attribute names and values are entirely processor specific so you must be aware of the implementation to figure them out. Read the documentation of your processor. For example, in Xalan 2.x:

  • http://xml.apache.org/xalan/features/optimize (boolean)
  • http://xml.apache.org/xalan/features/incremental (boolean)
  • ...
And in Saxon 8.x:
Constant IdFeatureType
ALLOW_EXTERNAL_FUNCTIONShttp://saxon.sf.net/feature/allow-external-functionsboolean
COLLATION_URI_RESOLVERhttp://saxon.sf.net/feature/collation-uri-resolver?
COLLECTION_URI_RESOLVERhttp://saxon.sf.net/feature/collection-uri-resolver?
DTD_VALIDATIONhttp://saxon.sf.net/feature/validation?
LINE_NUMBERINGhttp://saxon.sf.net/feature/linenumberingInteger
MESSAGE_EMITTER_CLASShttp://saxon.sf.net/feature/messageEmitterClass?
NAME_POOLhttp://saxon.sf.net/feature/namePool?
OUTPUT_URI_RESOLVERhttp://saxon.sf.net/feature/outputURIResolver?
RECOGNIZE_URI_QUERY_PARAMETERShttp://saxon.sf.net/feature/recognize-uri-query-parameters?
RECOVERY_POLICYhttp://saxon.sf.net/feature/recoveryPolicy?
SCHEMA_VALIDATIONhttp://saxon.sf.net/feature/schema-validationinteger
SOURCE_PARSER_CLASShttp://saxon.sf.net/feature/sourceParserClass?
STRIP_WHITESPACEhttp://saxon.sf.net/feature/strip-whitespace?
STYLE_PARSER_CLASShttp://saxon.sf.net/feature/styleParserClass?
TIMINGhttp://saxon.sf.net/feature/timingboolean
TRACE_EXTERNAL_FUNCTIONShttp://saxon.sf.net/feature/trace-external-functions?
TRACE_LISTENERhttp://saxon.sf.net/feature/traceListenerString
TREE_MODELhttp://saxon.sf.net/feature/treeModelInteger
VALIDATION_WARNINGShttp://saxon.sf.net/feature/validation-warnings?
VERSION_WARNINGhttp://saxon.sf.net/feature/version-warning?
XML_VERSIONhttp://saxon.sf.bet/feature/xml-version?

Parameters

AttributeDescriptionRequired
namename of the attributeYes
valuevalue of the attribute.Yes

since Ant 1.6.5.

Examples

<xslttest src="main/src/xslt" target="target/output" generate="true">	<fileset dir="main/test/xslt">		<include name="standalone*.xml" />		<include name="*.xsl" />		<exclude name="failing-sample.xsl" />	</fileset>	<factory name="net.sf.saxon.TransformerFactoryImpl"/></xslttest>

runs the unit tests main/test/xslt/standalone*.xml and main/test/xslt/*.xsl but excluding main/test/xslt/failing-sample.xsl. The "Tennison tests" templates are located in the main/src/xslt folder and the results generated in the target/output folder. This uses the Saxon transformation engine.

<xslttest src="main/src/xslt" target="target/output">	<fileset dir="${xslttest}">		<include name="**/standalone*.xml" />		<exclude name="failing-sample.xsl" />	</fileset>	<factory name="com.saxonica.SchemaAwareTransformerFactory">		<attribute name="http://saxon.sf.net/feature/allow-external-functions" value="true"/>		<attribute name="http://saxon.sf.net/feature/schema-validation" value="2"/>		<attribute name="http://saxon.sf.net/feature/validation-warnings" value="true"/>	</factory></xslttest>

runs the unit tests as for the previous example (but against main/test/xslt/standalone*.xml only. Uses the Saxon Schema Aware (SA) parser with some features set. NB: if you're using the SA parser, you'll need a valid licence file available to the classpath. This can be done with the following;

set CLASSPATH=%CLASSPATH%;[folder]

where [folder] is the folder where the license file (saxon-license.lic for example) exsists.

or use the licensefolder attribute.

<xslttest src="main/src/xslt" target="target/output" generate="false">	<fileset dir="${xslttest}">		<include name="TEST-sample.xsl" />	</fileset>	<factory name="net.sf.saxon.TransformerFactoryImpl" /></xslttest>

runs the tests defined in the TEST-sample.xsl file. This file has been pre-generated, by setting the generate attribute to false, the task will not attempt to genereate tests using the generate-tests.xsl template.

See thewriting tests section to understand how to write pre-generated tests.