简体   繁体   中英

Passing parameters between jsp and xsl

I have a problem between my jsp page and xsl, i want pass a parameter between the jsp and the xsl but it is never set in the xsl.

JSP page ;

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<%!
    private String getVal(String param, HttpServletRequest request) {
        return request.getParameter("fname");
    }
%>
<%
    String num = getVal("value", request);
%>

<div id="section" class="col-xs-10 col-sm-10 col-md-8">
            <c:import url="/monXml.xml" var="inputDoc" />

            <c:import url="/viewAnnonce.xsl" var="stylesheet" />
            <x:transform xml="${inputDoc}" xslt="${stylesheet}" >
                 <x:param name="numAnnonce" value="${num}"/>
            </x:transform>

        </div>

XSL :

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="utf-8"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />

  <xsl:param name="numAnnonce"/>

 <xsl:template match="/">
    <xsl:template match="/">
        <!-- Creation de la liste des annonces -->
        <xsl:for-each select=".//annonce[attribute::id=$numAnnonce]">
            <div id="article" class="row"></div>
        </xsl:for-each>
 </xsl:template>

`

The getVal("value", request); return a correct value.

Thanks.

您已经使用JSP scriptlet声明了num变量,我认为您不能使用${num}来访问它,您是否可以尝试使用scriptlet来访问它:

<x:param name="numAnnonce" value="<%=num%>"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM