如何将参数传递到.xsl文件中的$(document).ready()



有一个windows应用程序,当点击按钮时,它会弹出一个网页。网页的格式构建在.xsl文件中,而内容则填充在.cs文件中。.xsl的标记中有一些.css,标记中有jquery,后面跟着一些html和.xsl代码。TABLE行的颜色是在标记中设置的,当页面加载时,需要根据服务器端的某些值进行更改。

有没有一种方法可以将该值从服务器端传递到.xsl端的jquery。

这是.xsl文件的一小部分

$( document ).ready(function() {
$("#tEntSetup tr.datarow").hide();
$("#tEntOrg tr.datarow").hide();
$("#tCoSetup tr.datarow").hide();
$("#tEmpCount tr.datarow").hide();
$("#tRuleCode tr.datarow").hide();
$('#tVersionDetails').on('click', 'tr.header',function(){
$(this).nextUntil('tr.header').slideToggle(200);
});
$('#tEntSetup').on('click', 'tr.header',function(){
$(this).nextUntil('tr.header').slideToggle(200);
});
$('#tEntOrg').on('click', 'tr.header',function(){
$(this).nextUntil('tr.header').slideToggle(200);
});
$('#tCoSetup').on('click', 'tr.header',function(){
$(this).nextUntil('tr.header').slideToggle(200);
});
$('#tEmpCount').on('click', 'tr.header',function(){
$(this).nextUntil('tr.header').slideToggle(200);
});
$('#tRuleCode').on('click', 'tr.header',function(){
$(this).nextUntil('tr.header').slideToggle(200);
});
$('#tVersionDetails tr.header').css('background-color','#0073C2');
});

table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr.datarow th {
background-color: #ffeedd;
}
.header {
background-color: #3EAA48;
color:#FFFFFF;
cursor: pointer;
}
.datarow{
background-color: whitesmoke;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="gridtable" id="tVersionDetails">
<tr class="header"><th colspan="2" class="Title">Version Details</th></tr>
<tr class="datarow">
<th>Title</th>
<th>Version</th>
</tr>
<xsl:for-each select="//Information/ProductInformation/VersionInfo/data">
<tr class="datarow">
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="version"/>
</td>
</tr>
</xsl:for-each>
</table>

非常感谢您查看我的问题,并帮助我。

public void GetProdInformation(bool useCustom,string connString)
{
ConnectionString = connString;
UseCustom = useCustom;
XmlDocument XD = new XmlDocument();`enter code here`
XmlElement root = XD.CreateElement("Information");
XmlElement si = XD.CreateElement("ProductInformation");
root.AppendChild(si);
DataSet dsProdInfo = null;
try
{
using (DBHelper helper = new DBHelper(GetConnString()))
{
helper.ClearParameters();
helper.CommandType = System.Data.CommandType.StoredProcedure;
helper.CommandText = "dbo.pro_product_info_get";
dsProdInfo = helper.ExecuteQuery();
if (dsProdInfo != null && dsProdInfo.Tables.Count > 0)
SetTableNames(ref dsProdInfo);
CheckForPayrollInstallation(dsProdInfo);
}
si.AppendChild(VersionInfo(XD, dsProdInfo));
si.AppendChild(PayrollInstalled(XD));
si.AppendChild(EnterpriseSetup(XD, dsProdInfo));
si.AppendChild(EnterpriseOrganizations(XD, dsProdInfo));
si.AppendChild(CompanySetup(XD, dsProdInfo));
si.AppendChild(EmployeeCount(XD, dsProdInfo));
si.AppendChild(DetailedCheckBox(XD));
if (IsDetailedCheckBoxChecked)
si.AppendChild(RuleCodeTables(XD, dsProdInfo));
root.AppendChild(si);
XD.AppendChild(root);
String sLogFileName = string.Format(XMLFileName, Path.GetTempPath());
XD.Save(sLogFileName);
}
catch (Exception ex)
{
}
finally
{
dsProdInfo.Dispose();
}
}

您应该编辑原始问题,而不是添加答案,这样所有信息都在同一个位置。

您的服务器端代码没有显示xsl转换。它将是这样的:

string serverside_p = "a value";
XsltArgumentList argsList = new XsltArgumentList();
argsList.AddParam("serverside_param", "", serverside_p);
XslCompiledTransform transform = new XslCompiledTransform(true);
transform.Load("your_xsl.xsl");
using (StreamWriter sw = new StreamWriter("result.xml"))
{
transform.Transform("your_xml.xml", argsList, sw);
}

XSL需要有一个与传递的参数名称匹配的参数:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:param name="serverside_param" />
....
<!-- To output the value -->
<xsl:value-of select="$serverside_param" />
<!-- or put it inside an attribute value -->
<td class="{$serverside_param}_class">cell value </td>

但是,当您在服务器上构建XML时,为什么不能将参数值直接添加到XML中,并像访问任何其他XML属性一样访问它呢?

最新更新