♣
怎样实现这样的xslt?
<track>
<img>1.jpg</img>
<img>2/jpg</img>
....
</track>
想把图片放在单独的表格里,每行显示4个,如果多于四个则换行
谢谢
· 网友精彩回答:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"
xmlns:copyright="http://xml.sz.luohuedu.net/">
<xsl:template match="/">
<!-- 定义常量 -->
<xsl:variable name="strtrleft" select="<tr>"/>
<xsl:variable name="strtrright" select="</tr>"/>
<!-- 计算总记录数 -->
<xsl:variable name="ntotal" select="count(/items/item)"/>
<!-- 定义列数 -->
<xsl:variable name="ncols" select="3"/>
<!-- 计算需要的补齐的列数 -->
<xsl:variable name="nlefted" select="$ncols - ($ntotal mod $ncols)"/>
<!-- 计算不需要补齐的行数 -->
<xsl:variable name="nnotprocessedrow" select="$ntotal - ($ntotal mod $ncols)"/>
<table bgcolor="snow" border="1" cellpadding="5" cellspacing="2" bordercolor="darkorange"
style="font-size:9pt">
<!-- 对于不需要补齐的行数,直接输出 -->
<xsl:for-each select="/items/item[position() < $nnotprocessedrow +1]">
<xsl:if test="position() mod $ncols = 1">
<xsl:value-of select="$strtrleft" disable-output-escaping="yes"/>
</xsl:if>
<td>
<a target="_blank">
<xsl:attribute name="href">
<xsl:if test="contains(url,@)">mailto:</xsl:if><xsl:value-of select="url"/></xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
<xsl:if test="position() mod $ncols = 0">
<xsl:value-of select="$strtrright" disable-output-escaping="yes"/>
</xsl:if>
</xsl:for-each>
<!-- 转换除去不需要补齐的记录的剩余记录 -->
<xsl:if test="$nlefted != 0 and $nlefted != $ncols">
<xsl:value-of select="$strtrleft" disable-output-escaping="yes"/>
<xsl:for-each select="/items/item[position() >$nnotprocessedrow]">
<td>
<a target="_blank">
<xsl:attribute name="href">
<xsl:if test="contains(url,@)">mailto:</xsl:if><xsl:value-of select="url"/></xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
</xsl:for-each>
<!--
如果nlefted不等于0和列数,则需要进行补齐,这里进行递归调用,需要传递的参数有两个:
nlefted:要补齐的列数;
ncols:表格的列数。
-->
<xsl:call-template name="myfun">
<xsl:with-param name="nlefted" select="$nlefted"/>
<xsl:with-param name="ncols" select="$ncols"/>
</xsl:call-template>
<xsl:value-of select="$strtrright" disable-output-escaping="yes"/>
</xsl:if>
</table>
<p>共有<xsl:value-of select="$ntotal"/>条数据。</p>
</xsl:template>
<xsl:template name="myfun">
<xsl:param name="nlefted"/>
<xsl:param name="ncols"/>
<xsl:if test=" $nlefted != 0 and $nlefted != $ncols">
<td>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</td>
<xsl:call-template name="myfun">
<xsl:with-param name="nlefted" select="$nlefted - 1"/>
<xsl:with-param name="ncols" select="$ncols"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
从孟宪会之精彩世界 老大那里copy来的
关键是要考虑 表格列数不足的问题
- 更多问题:
- · 如何查询上月数据 的问题.急 急 急!!!
- · tomcat在windows20003sp1上使用80端口的问题
- · 接到过去领导打来的电话!!!!!(感动)
- · 请教,象下面这两种情况用不用手工释放内存
- · PB下面如何实现关机?
- · 打印机共享问题???
- · 关于一个网上xml树型菜单例子的问题:
- · 为什么某些后缀的文件不能下载?
- · eclipse 3.0.2里怎么配置struts??
- · 想问一下,关于informix中的substring
- · 关于影子复制的问题
- · 模糊搜索的问题
- · 静态html文件中可以包含其他html文件么?
- · 保护共享软件的一个思路
- · 动态添加DATAGRID的绑定列怎么做!
- · 看看外行是如何充老大的

