百分求解xslt嵌套循环
我写了一个嵌套循环的xsl,但总说参数未定义,请各位xsl高手帮忙看看,谢谢
代码如下:
<xsl:template match="/">
<xsl:for-each select="NewDataSet/Table">
<xsl:variable name="temp" select="Code"/>
<xsl:call-template name="Product"/>
</xsl:for-each>
<xsl:template name="Product">
<tr><td><p style="font-weight:bold"><xsl:value-of select="Code"/><xsl:variable name="para" select="Code"/></p></td>
<td colspan="6"><p style="font-weight:bold"><xsl:value-of select="cProductDesc"/></p></td></tr>
<xsl:for-each select="NewDataSet/Table1[Code=$para]">--------这里出错:未定义参数
<xsl:call-template name="Detail"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="Detail">
<TR>
<TD>
</TD>
<TD >
<xsl:value-of select="substring-before(Date,'T')"/>
</TD>
<TD class="SearchResultItem" align="center">
<xsl:value-of select="cClasseDesc_En"/>
</TD>
<TD>
<xsl:value-of select="Stock_Before"/>
</TD>
<TD >
<xsl:value-of select="StockQty"/>
</TD>
<TD >
<xsl:value-of select="Agent"/>
</TD>
<TD>
<xsl:value-of select="substring-before(ModifTime,'T')"/>
</TD>
</TR>
</xsl:template>
[解决办法]
"NewDataSet/Table1"---是未命名时的默认值 建议lz察看一下dataset中table是否被命名
[解决办法]
<xsl:for-each select="NewDataSet/Table1[Code=$para]" >--------这里出错:未定义参数
把xsl和xml都发上来让大家看看O.o
[解决办法]
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
<xsl:template match="/" >
<xsl:for-each select="NewDataSet/Table" >
<xsl:variable name="temp" select="Code" />
<table>
<xsl:call-template name="Product">
</xsl:call-template>
</table>
</xsl:for-each >
</xsl:template>
<xsl:template name="Product" >
<tr > <td > <p style="font-weight:bold" > <xsl:value-of select="Code" /> <xsl:variable name="para" select="Code" /> </p > </td >
</tr >
<xsl:for-each select="/NewDataSet/Table1[Code=$para]" >
<xsl:call-template name="Detail">
</xsl:call-template>
</xsl:for-each >
</xsl:template>
<xsl:template name="Detail" >
<TR >
<TD >
</TD >
<TD >
<xsl:value-of select="substring-before(Date, 'T ')" />
</TD >
<TD class="SearchResultItem" align="center" >
<xsl:value-of select="cClasseDesc_En" />
</TD >
<TD >
<xsl:value-of select="Stock_Before" />
</TD >
<TD >
<xsl:value-of select="StockQty" />
</TD >
<TD >
<xsl:value-of select="Agent" />
</TD >
<TD >
<xsl:value-of select="substring-before(ModifTime, 'T ')" />
</TD >
</TR >
</xsl:template >
</xsl:stylesheet>
你写的太乱了。 我给你改好了。
<xsl:for-each select="/NewDataSet/Table1[Code=$para]" > 看这里。
[解决办法]
我不知道,你申明了什么名称空间,我测试完。你发的XML片段,和我修改后的XSLT没有出现问题。
XML
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<NewDataSet >
<Table >
<Code >ABC </Code >
<Desc >Good </Desc >
</Table >
<Table >
<Code >BCD </Code >
<Desc >New </Desc >
</Table >
<Table1 >
<cClass >Standard </cClass >
<Code >ABC </Code >
<Date >2004-08-06 </Date >
<Time >12:50:33-04:00 </Time >
<Agent >Ray </Agent >
<Stock >300 </Stock >
</Table1 >
<Table1 >
<cClass >Standard </cClass >
<Code >BCD </Code >
<Date >2005-08-06 </Date >
<Time >12:50:33-04:00 </Time >
<Agent >Mike </Agent >
<Stock >100 </Stock >
</Table1 >
</NewDataSet >
XSLT
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" >
<xsl:template match="/" >
<xsl:for-each select="NewDataSet/Table" >
<xsl:variable name="temp" select="Code" />
<table >
<xsl:call-template name="Product" >
</xsl:call-template >
</table >
</xsl:for-each >
</xsl:template >
<xsl:template name="Product" >
<tr > <td > <p style="font-weight:bold" > <xsl:value-of select="Code" /> <xsl:variable name="para" select="Code" /> </p > </td >
</tr >
<xsl:for-each select="/NewDataSet/Table1[Code=$para]" >
<xsl:call-template name="Detail" >
</xsl:call-template >
</xsl:for-each >
</xsl:template >
<xsl:template name="Detail" >
<TR >
<TD >
</TD >
<TD >
<xsl:value-of select="substring-before(Date, 'T ')" />
</TD >
<TD class="SearchResultItem" align="center" >
<xsl:value-of select="cClasseDesc_En" />
</TD >
<TD >
<xsl:value-of select="Stock_Before" />
</TD >
<TD >
<xsl:value-of select="StockQty" />
</TD >
<TD >
<xsl:value-of select="Agent" />
</TD >
<TD >
<xsl:value-of select="substring-before(ModifTime, 'T ')" />
</TD >
</TR >
</xsl:template>
</xsl:stylesheet>