如何在products.xsl的主体中编写xsl,它将获得数量为>的产品名称和条件; 10
products.xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<products>
<product>
<name>soaps</name>
<quantity>10</quantity>
<condition>ready</condition>
</product>
<product>
<name>soaps</name>
<quantity>15</quantity>
<condition>ready</condition>
</product>
<product>
<name>soaps</name>
<quantity>20</quantity>
<condition>ready</condition>
</product>
</products>
products.xsl
<?xml version="1.0"?><!-- DWXMLSource="products.xml" -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE> products</TITLE>
</HEAD>
<BODY>
products quantity greater than 10 : <BR/>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:2)
这应该可以解决问题:
<xsl:for-each select="/products/product">
<xsl:if test="quantity > 10">
<xsl:value-of select="name" />: <xsl:value-of select="condition" /> <br/>
</xsl:if>
</xsl:for-each>
答案 1 :(得分:1)
这应该有效:(如果提供格式良好的XML - 请参阅问题评论)
<BODY> products quantity greater than 10 : <BR/>
<xsl:apply-templates select="//product[quantity > 10]"/>
</BODY>
结合例如这个模板:
<xsl:template match="product">
<P>
<xsl:value-of select="name"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="condition"/>
</P>
</xsl:template>
根据您的需求进行定制......
答案 2 :(得分:0)
此转化(无<xsl:for-each>
且无条件指示):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="product[quantity > 10]">
<p>
Product: <xsl:value-of select="name"/>
contition: <xsl:value-of select="condition"/>
quantity: <xsl:value-of select="quantity"/>
</p>
</xsl:template>
<xsl:template match="product"/>
</xsl:stylesheet>
应用于提供的XML文档时:
<products>
<product>
<name>soaps</name>
<quantity>10</quantity>
<condition>ready</condition>
</product>
<product>
<name>soaps</name>
<quantity>15</quantity>
<condition>ready</condition>
</product>
<product>
<name>soaps</name>
<quantity>20</quantity>
<condition>ready</condition>
</product>
</products>
产生想要的结果:
<p>
Product: soaps
contition: ready
quantity: 15</p>
<p>
Product: soaps
contition: ready
quantity: 20</p>