有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java XSLT参数不起作用

以下是我的java代码,与参数相关:

    transformer.setParameter("limad","1234");
    transformer.transform(text, new StreamResult(response.getOutputStream()));

我的xslt有:

<xsl:template match="/">
    <xsl:param name="limad"/>
    .... lots of stuff here...
                                <td>
                                    <xsl:value-of select="$limad"/>
                                </td>
    .... lots of stuff here...
</xsl:template>

我的结果是: <;td></td>

有什么想法吗?我如何调试这个


共 (1) 个答案

  1. # 1 楼答案

    我不是java方面的专家,但如果您试图将参数传递到xslt中,则需要将其置于模板匹配=“/”之外

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    
    
    <!  Imports  >
    <xsl:import href="test.xslt"/>
    
    <xsl:output method="html"
                      doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
                      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
                      indent="yes" standalone="yes"/>
    
     <!  Parameters >
    <xsl:param name="limad"/>
    
    <!  Templates Match >
    <xsl:template match="/">
        .... lots of stuff here...
                                    <td>
                                        <xsl:value-of select="$limad"/>
                                    </td>
        .... lots of stuff here...
    </xsl:template>
    </xsl:stylesheet>