以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  关于for-each的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=7121)


--  作者:血痕
--  发布时间:4/29/2004 1:35:00 PM

--  关于for-each的问题
for-each是否能实现js里面for(var i=0;i<100;i+=5)的功能?就是将“步长”设为5而不是1,如果不行我该怎样实现这个功能?xsl里不能改变变量的值,这样岂不是很不方便?虽然用 js可以实现但是好像如果在xsl里用了js,就不能把xml转换成html了,页面一片空白。。。
--  作者:sam
--  发布时间:4/29/2004 3:12:00 PM

--  
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
 <xsl:call-template name="for-loop">
  <xsl:with-param name="tempnode" select="//product"/>
  <xsl:with-param name="testValue" select="count(//product)"/>
 </xsl:call-template> 
</xsl:template>

 <xsl:template name="for-loop">
  <xsl:param name="tempnode" select="/"/>
  <xsl:param name="i"         select="1"/>
  <xsl:param name="increment" select="3"/>
  <xsl:param name="testValue" select="10"/>  

  <xsl:value-of select="$tempnode[$i]"/><br/>
  
  <xsl:variable name="contd">
   <xsl:choose>
    <xsl:when test="$i &lt; $testValue"><xsl:value-of select="1"/></xsl:when>
    <xsl:otherwise><xsl:value-of select="0"/></xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  
  <xsl:if test="number($contd)">
   <xsl:call-template name="for-loop">
    <xsl:with-param name="tempnode" select="$tempnode"/>
    <xsl:with-param name="i" select="$i + $increment"/>
    <xsl:with-param name="increment" select="$increment"/>
    <xsl:with-param name="testValue" select="$testValue"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>


<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="1.xslt" ?>
<products>
 <product>办公室圆桌</product>
 <product>老花眼镜</product>
 <product>家用弹簧秤</product>
 <product>手提电脑包</product>
 <product>电视天线</product>
 <product>智力拼图</product>
 <product>绘图工具</product>
 <product>硬面笔记本</product>
 <product>农场机械</product>
 <product>玩具小丑</product>
 <product>潜水装备</product>
</products>


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
25.391ms