首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

球xml加载xslt显示有关问题

2012-03-12 
球高手指点xml加载xslt显示问题a.xml内容如下:?xmlversion 1.0encoding utf-8??xml-stylesheettype

球高手指点xml加载xslt显示问题
a.xml
内容如下:

<?xml   version= '1.0 '   encoding= 'utf-8 '   ?>
<?xml-stylesheet   type= 'text/xsl '   href= 'b.xslt '   ?>
<a>
<b>
<b1> 1 </b1>
<b2> q </b2>
</b>
<b>
<b1> 2 </b1>
<b2> w </b2>
</b>
<b>
<b1> 3 </b1>
<b2> e </b2>
</b>
<b>
<b1> 4 </b1>
<b2> r </b2>
</b>
</a>


b.xslt
内容如下:

<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<xsl:stylesheet   version= "2.0 "   xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "   xmlns:xs= "http://www.w3.org/2001/XMLSchema "   xmlns:fn= "http://www.w3.org/2005/xpath-functions "   xmlns:xdt= "http://www.w3.org/2005/xpath-datatypes ">
<xsl:template   match= "/ ">
<html>
<head>
<title> test </title>
</head>

<body>
<table   width= "200 "   border= "1 ">
<tr>
<td   colspan= "2 "   align= "center "> test </td>
</tr>
<!--循环tr-->
<xsl:for-each   select= "a/b ">
<tr   bgcolor= "yellow ">
<td   align= "center "   width= "50% "> <xsl:value-of   select= "b1 "   /> </td>
<td   align= "center "   width= "50% "> <xsl:value-of   select= "b2 "   /> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


在不改变xml数据的情况下。XSLT如何控制表格的循环。就是一行黄色,一行绿色。
除了表格的标题外,循环部分以黄、绿色交替出现。

球高手指点。。在线等。。


[解决办法]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="C:\Documents and Settings\Administrator\My Documents\Untitled2.xsl"?>
<root>
<item>1111</item>
<item>1111</item>
<item>1111</item>
<item>1111</item>
<item>1111</item>
</root>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<table>
<tbody>
<tr>
<th>标题</th>
</tr>
</tbody>
<xsl:for-each select="//item">
<xsl:element name="tr">
<xsl:choose>
<xsl:when test="position() mod 2 =1">
<xsl:attribute name="style">background:yellow</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">background:green</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="."/></td>
</xsl:element>
</xsl:for-each>


</table>
</xsl:template>
</xsl:stylesheet>

热点排行