java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4094
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use Xslt/Style task E-mail
User Rating: / 3
PoorBest 

Xslt/Style

Description

Process a set of documents via XSLT.

This is useful for building views of XML based documentation, or for generating code.

Note: If you are using JDK 1.4 or higher, this task does not require external libraries not supplied in the Ant distribution. Otherwise, see Library Dependencies for more information.

It is possible to refine the set of files that are being processed. This can be done with the includes, includesfile, excludes, excludesfile and defaultexcludes attributes. With the includes or includesfile attribute you specify the files you want to have included by using patterns. The exclude or excludesfile attribute is used to specify the files you want to have excluded. This is also done with patterns. And finally with the defaultexcludes attribute, you can specify whether you want to use default exclusions or not. See the section on directory based tasks, on how the inclusion/exclusion of files works, and how to write patterns.

This task forms an implicit FileSet and supports all attributes of <fileset> (dir becomes basedir) as well as the nested <include>, <exclude> and <patternset> elements.

Note: Unlike other similar tasks, this task treats directories that have been matched by the include/exclude patterns of the implicit fileset in a special way. It will apply the stylesheets to all files contain in them as well. Since the default include pattern is ** this means it will apply the stylesheet to all files. If you specify an excludes pattern, it may still work on the files matched by those patterns because the parent directory has been matched. If this behavior is not what you want, set the scanincludedirectories attribute to false.

This task supports the use of a nested <param> element which is used to pass values to an <xsl:param> declaration.

This task supports the use of a nested xmlcatalog element which is used to perform Entity and URI resolution

<style> and <xslt> refer to the same Ant task and can be used interchangeably.

If you want to use Xalan-J 1 or XSL:P, you also need Ant's optional.jar

Parameters

Attribute Description Required
basedir where to find the source XML file, default is the project's basedir. No
destdir directory in which to store the results. Yes, unless in and out have been specified.
extension desired file extension to be used for the targets. If not specified, the default is ".html". Will be ignored if a nested <mapper> has been specified. No
style name of the stylesheet to use - given either relative to the project's basedir or as an absolute path DEPRECATED - can be specified as a path relative to the basedir attribute of this task as well. Yes
classpath the classpath to use when looking up the XSLT processor. No
classpathref the classpath to use, given as reference to a path defined elsewhere. No
force Recreate target files, even if they are newer than their corresponding source files or the stylesheet. No; default is false
processor name of the XSLT processor to use. Permissible values are "trax" for a TraX compliant processor (ie JAXP interface implementation such as Xalan 2 or Saxon), "xslp" for the XSL:P processor, "xalan" for the Apache XML Xalan (version 1) processor the name of an arbitrary XSLTLiaison class. Defaults to trax, followed by xalan and then xslp (in that order). The first one found in your class path is the one that is used. DEPRECATED - XSL:P and xalan are deprecated and no more supported.. No
includes comma- or space-separated list of patterns of files that must be included. All files are included when omitted. No
includesfile the name of a file. Each line of this file is taken to be an include pattern No
excludes comma- or space-separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted. No
excludesfile the name of a file. Each line of this file is taken to be an exclude pattern No
defaultexcludes indicates whether default excludes should be used or not ("yes"/"no"). Default excludes are used when omitted. No
in specifies a single XML document to be styled. Should be used with the out attribute. No
out specifies the output name for the styled result from the in attribute. No
scanincludeddirectories If any directories are matched by the includes/excludes patterns, try to transform all files in these directories. Default is true No
reloadstylesheet Control whether the stylesheet transformer is created anew for every transform opertaion. If you set this to true, performance may suffer, but you may work around a bug in certain Xalan-J versions. Default is false. Since Ant 1.5.2. No

Parameters specified as nested elements

classpath

The classpath to load the processor from can be specified via a nested <classpath>, as well - that is, a path-like structure.

xmlcatalog

The xmlcatalog element is used to perform Entity and URI resolution.

param

Param is used to pass a parameter to the XSL stylesheet.

Parameters

Attribute Description Required
name Name of the XSL parameter Yes
expression Text value to be placed into the param.
Was originally intended to be an XSL expression.
Yes
if The param will only passed if this property is set. No
unless The param will only passed unless this property is set. No

outputproperty ('trax' processors only)

Used to specify how you wish the result tree to be output as specified in the XSLT specifications.

Parameters

Attribute Description Required
name Name of the property Yes
value value of the property. Yes

factory ('trax' processors only)

Used to specify factory settings.

Parameters

Attribute Description Required
name fully qualified classname of the transformer factory to use. For example org.apache.xalan.processor.TransformerFactoryImpl or org.apache.xalan.xsltc.trax.TransformerFactoryImpl or net.sf.saxon.TransformerFactoryImpl... No. Defaults to the JAXP lookup mechanism.

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 7.x:
  • http://saxon.sf.net/feature/allow-external-functions (boolean)
  • http://saxon.sf.net/feature/timing (boolean)
  • http://saxon.sf.net/feature/traceListener (string)
  • http://saxon.sf.net/feature/treeModel (integer)
  • http://saxon.sf.net/feature/linenumbering (integer)
  • ...

Parameters

Attribute Description Required
name Name of the attribute Yes
value value of the attribute. Yes

mapper

since Ant 1.6.2

You can define filename transformations by using a nested mapper element. The default mapper used by <xslt> removes the file extension from the source file and adds the extension specified via the extension attribute.

Examples


<style basedir="doc" destdir="build/doc"
       extension=".html" style="style/apache.xsl"/>

Using an xmlcatalog

<xslt basedir="doc" destdir="build/doc"
      extension=".html" style="style/apache.xsl">
  <xmlcatalog refid="mycatalog"/>

</xslt>

<xslt basedir="doc" destdir="build/doc"
   extension=".html" style="style/apache.xsl">
   <xmlcatalog>

       <dtd
         publicId="-//ArielPartners//DTD XML Article V1.0//EN"
         location="com/arielpartners/knowledgebase/dtd/article.dtd"/>
   </xmlcatalog>
</xslt>

Using XSL parameters

<xslt basedir="doc" destdir="build/doc"
      extension=".html" style="style/apache.xsl">
  <param name="date" expression="07-01-2000"/>

</xslt>

Then if you declare a global parameter "date" with the top-level element <xsl:param name="date"/>, the variable $date will subsequently have the value 07-01-2000.

Using output properties

<xslt in="doc.xml" out="build/doc/output.xml"
      style="style/apache.xsl">
  <outputproperty name="method" value="xml";/>

  <outputproperty name="standalone" value="yes"/>
  <outputproperty name="encoding" value="iso8859_1"/>
  <outputproperty name="indent" value="yes"/>

</xslt>

Using factory settings

<xslt in="doc.xml" out="build/doc/output.xml"
   style="style/apache.xsl">

  <factory name="org.apache.xalan.processor.TransformerFactoryImpl">
    <attribute name="http://xml.apache.org/xalan/features/optimize"  
    value="true"/>
    </factory>
  </xslt>

Using a mapper

<xslt basedir="in" destdir="out"
      style="style/apache.xsl">
  <mapper type="glob" from="*.xml.en" to="*.html.en"/>

</xslt>

Copyright © 2000-2005 The Apache Software Foundation. All rights Reserved.

Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.