Class XsltTransformer
java.lang.Object
cloud.opencode.base.xml.transform.XsltTransformer
XSLT Transformer - XSLT stylesheet transformation
XSLT 转换器 - XSLT 样式表转换
This class provides XSLT transformation capabilities with a fluent API.
此类提供具有流式 API 的 XSLT 转换功能。
Usage Examples | 使用示例:
// Transform XML using XSLT stylesheet
String result = XsltTransformer.of(xslt)
.parameter("title", "My Document")
.transform(xml);
// Transform to file
XsltTransformer.of(xsltPath)
.transform(xmlPath, outputPath);
// Transform to XmlDocument
XmlDocument doc = XsltTransformer.of(xslt)
.transformToDocument(xml);
Features | 主要功能:
- XSLT stylesheet transformation - XSLT 样式表转换
- Fluent API with parameter support - 带参数支持的流式 API
- Transform to string, file, or XmlDocument - 转换到字符串、文件或 XmlDocument
Security | 安全性:
- Thread-safe: No (mutable parameters) - 线程安全: 否(可变参数)
- Null-safe: No (throws on null XSLT/XML) - 空值安全: 否(null XSLT/XML 抛异常)
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionClears all parameters.Sets the output encoding.Gets the underlying Templates object.indent(boolean indent) Sets whether to indent output.Sets the output method (xml, html, text).static XsltTransformerof(InputStream input) Creates a transformer from an XSLT input stream.static XsltTransformerCreates a transformer from an XSLT string.static XsltTransformerCreates a transformer from an XSLT file.omitXmlDeclaration(boolean omit) Sets whether to omit XML declaration.outputProperty(String name, String value) Sets an output property.Sets a transformation parameter.parameters(Map<String, Object> params) Sets multiple transformation parameters.transform(XmlDocument document) Transforms an XmlDocument.transform(InputStream input) Transforms from input stream to string.Transforms an XML string.voidtransform(String xml, OutputStream output) Transforms to an output stream.voidTransforms from file to file.transformFile(Path path) Transforms from file to string.transformToDocument(XmlDocument document) Transforms an XmlDocument to XmlDocument.Transforms an XML string to XmlDocument.
-
Method Details
-
of
Creates a transformer from an XSLT string. 从 XSLT 字符串创建转换器。- Parameters:
xslt- the XSLT stylesheet | XSLT 样式表- Returns:
- a new transformer | 新转换器
-
of
Creates a transformer from an XSLT file. 从 XSLT 文件创建转换器。- Parameters:
path- the XSLT file path | XSLT 文件路径- Returns:
- a new transformer | 新转换器
-
of
Creates a transformer from an XSLT input stream. 从 XSLT 输入流创建转换器。- Parameters:
input- the XSLT input stream | XSLT 输入流- Returns:
- a new transformer | 新转换器
-
parameter
Sets a transformation parameter. 设置转换参数。- Parameters:
name- the parameter name | 参数名称value- the parameter value | 参数值- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
parameters
Sets multiple transformation parameters. 设置多个转换参数。- Parameters:
params- the parameters map | 参数映射- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
clearParameters
Clears all parameters. 清除所有参数。- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
outputProperty
Sets an output property. 设置输出属性。- Parameters:
name- the property name | 属性名称value- the property value | 属性值- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
method
Sets the output method (xml, html, text). 设置输出方法(xml、html、text)。- Parameters:
method- the output method | 输出方法- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
encoding
Sets the output encoding. 设置输出编码。- Parameters:
encoding- the encoding | 编码- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
indent
Sets whether to indent output. 设置是否缩进输出。- Parameters:
indent- whether to indent | 是否缩进- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
omitXmlDeclaration
Sets whether to omit XML declaration. 设置是否省略 XML 声明。- Parameters:
omit- whether to omit | 是否省略- Returns:
- this transformer for chaining | 此转换器以便链式调用
-
transform
-
transform
Transforms an XmlDocument. 转换 XmlDocument。- Parameters:
document- the XML document | XML 文档- Returns:
- the transformed result | 转换结果
-
transform
Transforms from input stream to string. 从输入流转换为字符串。- Parameters:
input- the input stream | 输入流- Returns:
- the transformed result | 转换结果
-
transformFile
-
transform
-
transform
Transforms to an output stream. 转换到输出流。- Parameters:
xml- the XML string | XML 字符串output- the output stream | 输出流
-
transformToDocument
Transforms an XML string to XmlDocument. 将 XML 字符串转换为 XmlDocument。- Parameters:
xml- the XML string | XML 字符串- Returns:
- the transformed document | 转换后的文档
-
transformToDocument
Transforms an XmlDocument to XmlDocument. 将 XmlDocument 转换为 XmlDocument。- Parameters:
document- the XML document | XML 文档- Returns:
- the transformed document | 转换后的文档
-
getTemplates
Gets the underlying Templates object. 获取底层 Templates 对象。- Returns:
- the Templates | Templates 对象
-