想用xslt实现这样的功能该怎样做?
关键词:xslt,tr,List,mod
Acai_net:
静态情况下: <tr> <td></td> <td></td> </tr> 现在有一个List怎样让它动态出现上面的情况,就是 position mod 2= 0 的时候要写下: <tr> 当position mod 2 !=0 时候写下:</tr> 我尝试了好几种办法都没有用。
moonpiazza:
try: /*** a.xml ***/ <?xml version="1.0" encoding="gb2312" ?> <?xml-stylesheet type="text/xsl" href=http://topic.csdn.net/t/20030827/10/a.xsl ?> <moonpiazza> <book ID="1"> <title>基于XML 的 ASP.NET开发</title> <price>42</price> <author>Dan Wahlin/王宝良</author> </book> <book ID="2"> <title>XML应用的UML建模技术</title> <price>32</price> <author>David Carlson/周靖 侯奕萌 沈金河等</author> </book> <book ID="3"> <title>极限编程研究</title> <price>70</price> <author>Giancarrio Succi/Michele Marchesi/张辉(译)</author> </book> <book ID="4"> <title>Design Patterns</title> <price>38</price> <author>Erich Gamma/Richard Helm/Ralph Johnson/John Vlissides</author> </book> </moonpiazza> /*** a.xsl ***/ <?xml version="1.0" encoding="gb2312"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="moonpiazza" > <table border="1"> <xsl:apply-templates select="book"/> </table> </xsl:template> <xsl:template match="book" > <xsl:if test="(position() mod 2) != 0"> <xsl:text disable-output-escaping="yes"> <![CDATA[ <tr> ]]> </xsl:text> </xsl:if> <td><xsl:value-of select="title" /></td> <xsl:if test="(position() mod 2) = 0"> <xsl:text disable-output-escaping="yes"> <![CDATA[ </tr> ]]> </xsl:text> </xsl:if> </xsl:template> </xsl:stylesheet> :_)
net_lover:
http://www.erp800.com/net_lover/ShowDetail.asp?id=YAWO3QGM-XD53-4D3D-OYBR-BLSBX5BNGAYM 用XSL把XML的数据转换成完美的多列表格形式