<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<HEAD><TITLE>Shopping Cart</TITLE></HEAD>
<xsl:apply-templates/>
</HTML>
<BODY>
<xsl:variable name="bookTotal" select="sum(//item/price)"/>
<xsl:variable name="bookCount" select="count(//item/itemNO)"/>
<DIV><xsl:value-of select="name"/></DIV>
<DIV><xsl:value-of select="email"/></DIV>
<DIV><xsl:value-of select="zipcode"/></DIV>
<DIV><xsl:value-of select="address"/></DIV>
<TABLE border="1">
<THEAD>
<TD><B>编号</B></TD>
<TD><B>书名</B></TD>
<TD><B>价格</B></TD>
<TD><B>出版社</B></TD>
</THEAD>
<xsl:for-each select="./item" >
<TR>
<TD><xsl:value-of select="itemNO"/></TD>
<TD><xsl:value-of select="itemName"/></TD>
<TD><xsl:value-of select="price"/></TD>
<TD><xsl:value-of select="publisher"/></TD>
</TR>
</xsl:for-each>
<TR><TD><B>总价</B></TD>
<TD ><xsl:value-of select="$priceTotal"/></TD>
<TD><B>数量</B></TD>
<TD><xsl:value-of select="$bookCount"/></TD>
</TR>
</TABLE>
</BODY>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<HEAD><TITLE>Shopping Cart</TITLE></HEAD>
<xsl:apply-templates/>
</HTML>
<BODY>
<xsl:variable name="bookTotal" select="sum(//item/price)"/>
<xsl:variable name="bookCount" select="count(//item/itemNO)"/>
<DIV><xsl:value-of select="name"/></DIV>
<DIV><xsl:value-of select="email"/></DIV>
<DIV><xsl:value-of select="zipcode"/></DIV>
<DIV><xsl:value-of select="address"/></DIV>
<TABLE border="1">
<THEAD>
<TD><B>编号</B></TD>
<TD><B>书名</B></TD>
<TD><B>价格</B></TD>
<TD><B>出版社</B></TD>
</THEAD>
<xsl:for-each select="./item" >
<TR>
<TD><xsl:value-of select="itemNO"/></TD>
<TD><xsl:value-of select="itemName"/></TD>
<TD><xsl:value-of select="price"/></TD>
<TD><xsl:value-of select="publisher"/></TD>
</TR>
</xsl:for-each>
<TR><TD><B>总价</B></TD>
<TD ><xsl:value-of select="$priceTotal"/></TD>
<TD><B>数量</B></TD>
<TD><xsl:value-of select="$bookCount"/></TD>
</TR>
</TABLE>
</BODY>
</xsl:template>
</xsl:stylesheet>
<?xml-stylesheet type="text/xsl" href="shoppingcart1.xsl"?>
<shoppingcart>
<customer>
<name>赵子龙</name>
<email>[email protected]</email>
<zipcode>361021</zipcode>
<address>中国福建厦门市</address>
</customer>
<shoppingItem>
<item>
<itemNO>1001</itemNO>
<itemName>三国演义</itemName>
<price>30.00</price>
<publisher>文艺出版社</publisher>
</item>
<item>
<itemNO>1002</itemNO>
<itemName>红楼梦</itemName>
<price>120.00</price>
<publisher>文艺出版社</publisher>
</item>
</shoppingItem>
</shoppingcart>
这是XML文档,但是运行不出来,为什么呢?显示的错误是解析不出变量bookTatal和bookcount,为什么呢
<TD > <xsl:value-of select="$priceTotal"/> </TD>
<TD> <B>数量 </B> </TD>
<TD> <xsl:value-of select="$bookCount"/> </TD>
</TR>
这句 $priceTotal 变量名字写错了 全文里就没有定义国他 你自己前面命名的变量名应该是叫“bookTotal”
至于bookCount 这个变量没有问题 只要把 $priceTotal 改成$ bookTotal就好了
<TD > <xsl:value-of select="$priceTotal"/> </TD>
<TD> <B>数量 </B> </TD>
<TD> <xsl:value-of select="$bookCount"/> </TD>
</TR>
这句 $priceTotal 变量名字写错了 全文里就没有定义国他 你自己前面命名的变量名应该是叫“bookTotal”
至于bookCount 这个变量没有问题 只要把 $priceTotal 改成$ bookTotal就好了