【问题标题】:how to pass parameter to $(document).ready() within .xsl file如何在 .xsl 文件中将参数传递给 $(document).ready()
【发布时间】:2020-12-08 01:56:34
【问题描述】:

有一个 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>

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

【问题讨论】:

  • 我没有看到对服务器的调用?您可以在 XSL 中包含一个 x,其值在转换之前由服务器设置,然后在 XSL 中用作:
  • Bryn - 参数如何从服务器端获取值?
  • 这取决于您如何进行转换。您还没有显示服务器端代码,但是有一种方法可以添加 xsl、xml 并向您定义的参数添加值。
  • Bryn - 以下是服务器端代码,它生成 xml 并插入 xsl。

标签: jquery css xslt styles


【解决方案1】:

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

您的服务器端代码未显示 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 属性一样访问它?

【讨论】:

    【解决方案2】:
    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();
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多