如何从 Java 编辑 xsl 标记属性文件



我有一个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文件并修改小程序标签的atrribute吗?

使用 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方法,其他引擎的工作方式类似。

顺便说一下,所有大写HTML最后一次使用是在90年代。

最新更新