我有一个 xsl 文件,用作模板,我需要在运行时修改它。我需要修改标签的属性值。有什么办法可以通过JAVA代码来做到这一点吗?我知道模板 xsl 文件的位置。
例如:
示例 xsl 模板:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:template match="Sample">
<HTML>
<HEAD>
</HEAD>
<BODY >
<APPLET ARCHIVE="http://localhost:500/abc.jar" CODE="test.class" NAME="Apps" ></APPLET>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
这里我需要修改APPLET标记,我需要在运行时设置ARCHIVE值,比如“http://localhost:800/xyz.jar”
我可以从Java somwhow读取这个xsl文件并修改applet标签的属性吗?
最佳答案
使用 XSL 参数传输值
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
>
<xsl:param name="archive" select="''" />
<xsl:output method="html" indent="yes" />
<xsl:template match="Sample">
<html>
<head />
<body>
<applet archive="{$archive}" code="test.class" name="Apps" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
了解如何在 XSLT 引擎中传递 XSL 参数。撒克逊人会使用 XsltTransformer.SetParameter
method ,其他引擎的工作原理类似。
顺便说一句,全大写 HTML 上次使用是在 90 年代。
关于java - 如何从 Java 编辑 xsl 标签属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19266732/