首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

在 xsl 中做用户筛选的有关问题

2012-12-21 
在 xsl 中做用户筛选的问题最近在做 xsl 解析, 在 xml 中通过 href 指定 xsl, 这样打开 xml 文件时, 可以

在 xsl 中做用户筛选的问题
最近在做 xsl 解析, 在 xml 中通过 href 指定 xsl, 这样打开 xml 文件时, 可以通过 href 指定的 xls 对 xml 做一个友好展示
现在的问题是, 准备在 xsl 中增加一个用户筛选, 允许用户对要看到的数据做进一步筛选

xml 示例如下 (filter.xml)


<?xml-stylesheet type="text/xsl" href="filter.xsl"?>
<root>
  <group name="group1">
    <item id="1">item 1</item>
    <item id="2">item 2</item>
  </group>
  <group name="group2">
    <item id="1">item a</item>
    <item id="2">item b</item>
  </group>
</root>


[最优解释]
推荐一下,以便更多的人关注
[其他解释]
路过...
[其他解释]
邹大版的贴,顶起
[其他解释]
引用:
邹大版的贴,顶起

转。NET 版
[其他解释]
引用:
邹大版的贴,顶起


没理由地顶起
[其他解释]
学习学习                                         
[其他解释]
不小心点了进来,看到那么多勋章晃花了眼,这究竟是一个什么样的问题?
看了后才发现差距了,xsl从来多没用过。
[其他解释]
对应的 xsl 如下

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/root">
    <xsl:param name="GroupName" select ="(group/@name)[1]"/>
    <html>
      <head>
        <meta content="text/html" http-equiv="Content-Type"></meta>

        <script language="javascript" name="Filter">
          <![CDATA[
function filter_group(sName) {
    var iXml = document.XMLDocument;
    var iXsl = document.XSLDocument;
    //iXsl.addParameter("GroupName", sName);  //

    var iPara = iXsl.selectSingleNode('//xsl:param[@name="GroupName"]');
    alert(iPara.text);

    var iHtml = iXml.transformNode(iXsl);
    document.write(iHtml);
}
]]>
        </script>
      </head>

      <body>
        <table>


          <tr>
            <td>
              <form style="BORDER: 0">
                <select id="frm_Server">
                  <option value="" selected="1"><![CDATA[<- Please Select ->]]></option>
                  <xsl:for-each select ="group/@name">
                    <xsl:sort select ="."/>
                    <option>
                      <xsl:attribute name ="value">
                        <xsl:value-of select="."/>
                      </xsl:attribute>
                      <xsl:value-of select="."/>
                    </option>
                  </xsl:for-each>
                  <option value="*"><![CDATA[<- ALL ->]]></option>
                </select>
                <button onClick="filter_group(this.form.frm_Server.value)">Query</button>
              </form>
            </td>
          </tr>
          <tr>
            <td>
              <xsl:apply-templates select="group[@name=$GroupName or $GroupName = '*']"/>
            </td>
          </tr>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="group">
    <table>
      <thead>
        <tr>
          <th>id</th>
          <th>value</th>
        </tr>


      </thead>
      <tbody>
        <xsl:for-each select="item">
          <tr>
            <td>
              <xsl:value-of select="@id"/>
            </td>
            <td>
              <xsl:value-of select="."/>
            </td>
          </tr>
        </xsl:for-each>
      </tbody>
    </table>
  </xsl:template>

</xsl:stylesheet>


[其他解释]
主要的问题在 js 部分
1. 不知道如何设置参数值
2. 通过 transformNode 处理之后 , 第2次再执行这段脚本, 就会出错

function filter_group(sName) {
    var iXml = document.XMLDocument;
    var iXsl = document.XSLDocument;
    //iXsl.addParameter("GroupName", sName);  //网上索引到这种设置参数, 提示没有这个方法

    var iPara = iXsl.selectSingleNode('//xsl:param[@name="GroupName"]');
    alert(iPara.text);// 这个可以找到参数节点, 但不辞谢如何赋值(不知道用那个属性

    var iHtml = iXml.transformNode(iXsl);
    document.write(iHtml);// 这个处理之后, 再次点 button 支持这段脚本, 就会出错
}



[其他解释]
WEB 版块太不给力了, 一天都没人理
转过来放水好了

当然, 有清楚的童鞋帮忙解决的话, 可以再转回技术版
[其他解释]
当时不努力老大不开心呀....看看软件
[其他解释]
学习学习
[其他解释]
好多花花绿绿的勋章哦!我是来看勋章的!
[其他解释]
自己搞定了
http://blog.csdn.net/zjcxc/article/details/7950418
[其他解释]
null
[其他解释]
null

热点排行