【发布时间】:2015-08-26 21:33:28
【问题描述】:
鉴于此 XML:
<?xml version="1.0" encoding="iso-8859-2" ?>
<r>
<products start="5" stop="8">
<p>
<id> 50 </id>
<name> Murphy </name>
<price> 33 </price>
</p>
<p>
<id> 10 </id>
<name> Margarethe </name>
<price> 11 </price>
</p>
</products>
<products start="1" stop="4">
<p>
<id> 555 </id>
<name> XXXX</name>
<price> 333 </price>
</p>
<p>
<id> 10 </id>
<name> Mexico </name>
<price> 11 </price>
</p>
</products>
<products start="1" stop="4">
<p>
<id> 30 </id>
<name> HKoney </name>
<price> 11 </price>
</p>
<p>
<id> 10 </id>
<name> HMargarethe </name>
<price> 11 </price>
</p>
</products>
</r>
使用此 XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:template match="products[@start < 2 and @stop > 2]" >
<xsl:call-template name="test"/>
</xsl:template>
<xsl:template name="test">
<test><xsl:value-of select="*/name"/></test>
</xsl:template>
<xsl:template match="products"/>
</xsl:stylesheet>
有这个输出:
<?xml version="1.0" encoding="UTF-8"?>
<test> XXXX</test>
<test> HKoney </test>
问:为什么我没有得到所有具有指定属性的父级的
<p>,只有第一个?Mexico和HMargarethe也是预期的。
期望的输出:
<?xml version="1.0" encoding="UTF-8"?>
<test> XXXX</test>
<test> Mexico </test>
<test> HKoney </test>
<test> HMargerethe</test>
注意:我希望它在没有
for-each循环的情况下工作。
【问题讨论】:
-
您希望单个
元素中的所有名称都出现在
中吗?请提供所需输出的示例 -
我已经输入了想要的输出。