喜悦国际村 » XML/HTML/CSS/Js » 请问个xsl中的script与eval的问题

页: [1]
太阳雨2005-6-4 10:49 AM
请问个xsl中的script与eval的问题

<xsl:template match = "channel" >
<table align="center" style="background-color:#e5e5e5;">
<tr><td  style="text-align:center">
<h1><xsl:value-of select="category"/>-<xsl:value-of select="title"/></h1>
<a target="_blank"><xsl:attribute name="href"><xsl:value-of select="link" /></xsl:attribute><xsl:value-of select="link"/></a><br />
<xsl:value-of select="copyright"/>
</td></tr>
</table>
<!--item项-->
<table align="center">
    <xsl:for-each select="item">
    <tr><td>
    <b><xsl:eval>cls(this)</xsl:eval></b>  (<xsl:value-of select="pubDate"/>)<br />
    <a target="_blank"><xsl:attribute name="href"><xsl:value-of select="link" /></xsl:attribute><xsl:value-of select="link"/></a><p />
    <xsl:value-of select="description"/>
    </td></tr>
    </xsl:for-each>
</table>

<xsl:script>
function cls(node){
//读取节点title的值,并处理(如去除空间)
var v=node.selectNodes('/channel/item/title');
//应该怎样返回该节点的值并在eavl中使用?
}
</xsl:script>
</xsl:template>

xiaocon2005-6-10 07:27 AM
xsl:script
没用过,以前用XSL的模板和变量做一些,下面贴个xsl文件,主要是一些xsl函数,以供参考。不过XSL写起来很麻烦,现在已经基本不使用了
[code]
<?xml version="1.0" encoding="gb2312"?>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" version="1.0" encoding="GB2312" indent="yes"/>
        <xsl:template name="getList">
                <xsl:param name="lstpath" />
                <xsl:param name="lstVal" />
            <xsl:for-each select="$lstpath">
                  <option value="{S_BM}">
                              <xsl:if test="$lstVal=S_BM">
                          <xsl:attribute name="selected">selected="true"</xsl:attribute>
                              </xsl:if>
                              <xsl:value-of select="S_BMMC" />          
                          </option>
                  </xsl:for-each>
        </xsl:template>
        <xsl:template name="getListText">
                <xsl:param name="lstpath" />
                <xsl:param name="lstVal" />
            <xsl:for-each select="$lstpath">
                              <xsl:if test="$lstVal=S_BM">
                                        <xsl:value-of select="S_BMMC" />
                              </xsl:if>
                  </xsl:for-each>
        </xsl:template>
       
       
        <xsl:template name="getMultipleListVal">
                 <xsl:param name="lstVal" />
                 <xsl:param name="lstText" />
                <xsl:param name="valPath" />
            <xsl:for-each select="$valPath">
                  <option value="{S_BM}">
                                      <xsl:if test="$lstVal=S_BM">
                                  <xsl:attribute name="selected">selected="true"</xsl:attribute>
                                      </xsl:if>
                                        <xsl:value-of select="$lstText" />         
                                </option>
                          </xsl:for-each>
        </xsl:template>                             
                             
        <xsl:template name="getMultipleList">
                <xsl:param name="lstpath" />               
            <xsl:for-each select="$lstpath">
                                <option value="{S_BM}">
                              <xsl:if test="isSelected=1">
                          <xsl:attribute name="selected">selected="true"</xsl:attribute>
                              </xsl:if>
                              <xsl:value-of select="S_BMMC" />          
                          </option>
                        </xsl:for-each>
        </xsl:template>

        <xsl:template name="syesno">
                <xsl:param name="iyesno" />
          <option value="否" >
                                    <xsl:if test="$iyesno='否'">
                        <xsl:attribute name="selected">selected="true"</xsl:attribute>
                  </xsl:if>
                  否</option>
          <option value="是">
                                    <xsl:if test="$iyesno='是'">
                        <xsl:attribute name="selected">selected="true"</xsl:attribute>
                  </xsl:if>
                  是</option>
        </xsl:template>
        <xsl:template name="yesno">
                <xsl:param name="iyesno" />
          <option value="0" >
                                    <xsl:if test="$iyesno='0'">
                        <xsl:attribute name="selected">selected="true"</xsl:attribute>
                  </xsl:if>
                  否</option>
          <option value="1">
                                    <xsl:if test="$iyesno='1'">
                        <xsl:attribute name="selected">selected="true"</xsl:attribute>
                  </xsl:if>
                  是</option>
        </xsl:template>
                <xsl:template name="stringyesno">
                <xsl:param name="iyesno" />
                          <xsl:if test="$iyesno='0'">否</xsl:if>
                  
                          <xsl:if test="$iyesno='1'">是</xsl:if>

        </xsl:template>

                <xsl:template name="getZT">
                        <xsl:param name="zt" />
          <option value="zc">
                                    <xsl:if test="$zt='zc'">
                        <xsl:attribute name="selected">selected="true"</xsl:attribute>
                  </xsl:if>
                  正常</option>
          <option value="qx">
                                    <xsl:if test="$zt='qx'">
                        <xsl:attribute name="selected">selected="true"</xsl:attribute>
                  </xsl:if>
                  取消</option>
          <option value="zx">
                                    <xsl:if test="$zt='zx'">
                        <xsl:attribute name="selected">selected="true"</xsl:attribute>
                  </xsl:if>
                  注销</option>
        </xsl:template>
</xsl:stylesheet>
[/code]
在调用的页面中
[code]
<?xml version="1.0" encoding="gb2312"?>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:import href="../xsl/public.xsl" />
        <xsl:output method="html" version="1.0" encoding="GB2312" indent="yes" />
        <xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
[/code]


查看完整版本: 请问个xsl中的script与eval的问题


Powered by Discuz! Archiver 6.1.0  © 2001-2006 Comsenz Inc.
Processed in 0.006251 second(s), 2 queries