XSL文件中的Java setParameter

时间:2011-12-26 12:18:33

标签: java xml xslt parameters

我在从XLS文件中添加参数的Java项目打印PDF文件时遇到问题。该项目读取XML文件,然后他从XSL样式表生成PDF文件。请参阅下面的文件内容 正如您在XLS文件中看到的那样,我希望在“studentNumber”中指定,但问题是指定的“studentNumber”需要在Java项目中设置。我尝试过很多东西并在互联网上搜索,但我找不到答案。 任何想法都希望我需要改变以使这个项目正常。

XML文件:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="studentResultXLS.xsl"?>
<cursus>
    <enroll>
        <studentnumber>s484766</studentnumber>
        <cursuscode>ISDTCEX.B627</cursuscode>
        <enrolldate dateformat="eejjmmdd">20111121</enrolldate>
        <acquire>ja</acquire>
        <grade>4</grade>
        <result></result>
    </enroll>
    <enroll>
        <studentnumber>s484766</studentnumber>
        <cursuscode>ISDTSIP.T470</cursuscode>
        <enrolldate dateformat="eejjmmdd">20111116</enrolldate>
        <acquire>ja</acquire><grade>2</grade>
        <result></result>
    </enroll>
    <enroll>
        <studentnumber>s484767</studentnumber>
        <cursuscode>ISDTSIP.T470</cursuscode>
        <enrolldate dateformat="eejjmmdd">20111116</enrolldate>
        <acquire>ja</acquire><grade>2</grade>
        <result></result>
    </enroll>

</cursus>

XLS文件:

<xsl:param name="studentnumber"/>.....

<fo:table-body>
    <xsl:for-each select="/cursus/enroll[studentnumber='s484766']">
        <fo:table-row>

            <fo:table-cell>
                <fo:block> <xsl:value-of select="studentnumber"/> </fo:block>
            </fo:table-cell>

                <fo:table-cell>
                    <fo:block> <xsl:value-of select="cursuscode"/> </fo:block>
                </fo:table-cell>
            </fo:table-row>
    </xsl:for-each>
    </fo:table-body>

Java代码:

 transformer.setParameter("studentnumber", "s484766");

1 个答案:

答案 0 :(得分:2)

要读取参数值,您需要在其前面添加$符号:

<xsl:value-of select="$studentnumber"/>