Html 编写XSL以对xml数据执行某些操作

Html 编写XSL以对xml数据执行某些操作,html,xml,xslt,Html,Xml,Xslt,如何在products.xsl的主体中编写xsl,以获得数量大于10的产品名称和条件 products.xml: <?xml version="1.0" encoding="iso-8859-1"?> <products> <product> <name>soaps</name> <quantity>10</quantity> <condition&g

如何在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>

肥皂
10
准备好的
肥皂
15
准备好的
肥皂
20
准备好的
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>

产品
大于10的产品数量:
这应该有效:(如果提供了格式良好的XML–请参阅对问题的评论)

大于10的产品数量:
与此模板结合使用,例如:

<xsl:template match="product">
    <P>
        <xsl:value-of select="name"/>
        <xsl:text>: </xsl:text>
        <xsl:value-of select="condition"/>
    </P>
</xsl:template>

:


只需根据您的需要进行定制…

这应该可以做到:

<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>


此转换(无
且无条件指令):



产品:
续:
数量:

应用于提供的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>

肥皂
10
准备好的
肥皂
15
准备好的
肥皂
20
准备好的
产生想要的结果

<p>
    Product: soaps
    contition: ready
    quantity: 15</p>
<p>
    Product: soaps
    contition: ready
    quantity: 20</p>

产品:香皂
继续:准备好了吗
数量:15

产品:香皂 继续:准备好了吗 数量:20


请检查示例products.xml,其开头/结尾标记似乎不正确。如果您使用缩进,您将更容易看到这一点。我认为您可以使用If case。@如何编写XSL来实现这一点?好问题,+1。请参阅我的答案,以获得完整、简短且简单的解决方案。:)输入是不需要
xsl:if
指令。
<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>