Xml 子对象值的筛选结果-xsl
我在尝试从xml获取数据时遇到问题,我得到了一个:Xml 子对象值的筛选结果-xsl,xml,xslt,Xml,Xslt,我在尝试从xml获取数据时遇到问题,我得到了一个: <?xml version="1.0" encoding="UTF-8"?> <base> <!-- OFFERS --> <offers> <offer status="1">Sale</offer> <offer status="2">Rent</offer> </offers> <!--CATEGOR
<?xml version="1.0" encoding="UTF-8"?>
<base>
<!-- OFFERS -->
<offers>
<offer status="1">Sale</offer>
<offer status="2">Rent</offer>
</offers>
<!--CATEGORIES-->
<categories>
<category cat="A">Category 1</category>
<category cat="B">Category 2</category>
<category cat="C">Category 3</category>
</categories>
<!--OBJECTS-->
<objects>
<object id="1" offer="1">
<name>Object 1</name>
<category cat="A"/>
<price>12</price>
</object>
<object id="2" offer="2">
<name>Object 1</name>
<category cat="B"/>
<price>1000</price>
</object>
<object id="3" offer="2">
<name>Object 1</name>
<category cat="A"/>
<price>10</price>
</object>
</objects>
<object id="4" offer="1">
<name>Object 1</name>
<category cat="C"/>
<price>60</price>
</object>
<object id="5" offer="2">
<name>Object 1</name>
<category cat="A"/>
<price>30</price>
</object>
</base>
对于每个类别,我需要知道租金/报价/报价价格的算术平均值
我的xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Category</th>
<th>AM</th>
</tr>
<xsl:for-each select="//categories/category">
<xsl:variable name="cat" select="@cat"/>
<xsl:variable name="object" select="//object[category/@cat=$cat]"/>
<xsl:variable name="qtobj" select="count($obj)"/>
<tr>
<td><xsl:value-of select="." /></td>
<td><xsl:value-of select="$object/price div $qtobj"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我的主要问题是,我不知道如何仅过滤租赁对象。如果我理解正确,您需要执行以下操作: XSLT1.0 按照您的方式,您可以定义:
<xsl:variable name="objects" select="//object[category/@cat=current()/@cat and @offer=$rent-status]"/>
但是使用a更有效,也更优雅。嗯,我也忘了其他事情。使用钥匙对我来说仍然很难,我需要多学一点,继续练习,谢谢
<xsl:variable name="objects" select="//object[category/@cat=current()/@cat and @offer=$rent-status]"/>