【问题标题】:Websphere - Transformer.setParameter not workingWebsphere - Transformer.setParameter 不起作用
【发布时间】:2017-05-23 22:22:33
【问题描述】:

我有一个 XSLT,我用它来使用 Java 转换 XML。当我在 Eclipse 中运行它并使用 Apache Tomcat 时,代码运行良好。但是当我将 ear 文件部署到 WebSphere 时,该字段显示为空白。有人有想法吗?

java 变量 'reportId' 和 'proposalId' 设置为我使用 System.out.println() 并且可以看到值已设置。

Java 代码 // 使用工厂创建包含 xsl 文件的模板

Templates template = factory.newTemplates(new StreamSource(is));              

// Use the template to create a transformer
Transformer xformer = template.newTransformer();
xformer.setParameter("reportId", reportId);
xformer.setParameter("proposalId", proposalId);


<xsl:param name="proposalId"/>
<xsl:param name="reportId"/>

然后我在 XSLT 中使用以下内容来读取参数:

<td align="left"><b>Proposal Ref: </b> <xsl:value-of select="$proposalId"/> </td> <td align="left"><b>Report Id: </b> <xsl:value-of select="$reportId"/> </td>

【问题讨论】:

    标签: java xml xslt websphere transformer


    【解决方案1】:

    我发现我在模板标签中有参数。转换器不能设置模板级变量的值。它只能在全局级别变量上设置它。所以我的代码是这样的:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:template match="/">
    
    <xsl:param name="proposalId"/>
    <xsl:param name="reportId"/>
    
    </xsl:template>
    </xsl:stylesheet>
    

    但它应该是:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:param name="proposalId"/>
    <xsl:param name="reportId"/>
    <xsl:template match="/">
    
    </xsl:template>
    </xsl:stylesheet>
    

    【讨论】:

      猜你喜欢
      • 2020-06-19
      • 1970-01-01
      • 2019-06-18
      • 2014-02-11
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多