让XSL在xml数据上执行一些操作 [英] wrirting XSL to perform some operations on xml data

查看:76
本文介绍了让XSL在xml数据上执行一些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在products.xsl的主体中编写xsl,以获得产品名称和条件,数量> 10

How to write xsl in the body of products.xsl that will get product name and condition with quantity > 10

products.xml:

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

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>


推荐答案

b
$ b

This should do the trick:

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

这篇关于让XSL在xml数据上执行一些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆