How to transform XML with XSLT processor in Java?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
JAXP provides a implementation independent way of working with XSLT transformations. Here is the tutorial to get you started. If you are working with huge XSLT and/or working with multiple XSLT's then there is also an option of caching the parsed XSLT templates for performance reasons. This article explains how to cache xslt's
Here is sample for using java api for transformer, as @Raedwald said:
The Java standard library provides an (XSLT) transformation interface for XML parsing. See the API documentation for the classes
javax.xml.transform.Transformer
andjavax.xml.transform.TransformerFactory
.This depends on which Java-based XSLT processor you are using. Each XSLT processor has its own API.
For example, Saxon 6.5.5 (for XSLT 1.0) and Saxon 9.1.07 (for XSLT 2.0) are written in Java. The documentation is at http://www.saxonica.com/documentation/documentation.xml
Almost all XSLT processors have a command-line utility, which doesn't require writing a program in order to perform an XSLT transformation.
For example, here is: how to start a Saxon 9.x transformation from the command line.
Here is how I always use Saxon from the command-line:
where
%out%
is the name of the output file,%xml%
is the xml file,%xsl%
is the primary xslt file and%param[ name=\"value\"]%
is a name-value list of external parameters (I almost always leave this empty).