Given this 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>
With this 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>
Having this output:
<?xml version="1.0" encoding="UTF-8"?>
<test> XXXX</test>
<test> HKoney </test>
Q : Why am I not getting all the
<p>
with parent of specified attributes, only the first one?Mexico
andHMargarethe
was expected also.
Desired output:
<?xml version="1.0" encoding="UTF-8"?>
<test> XXXX</test>
<test> Mexico </test>
<test> HKoney </test>
<test> HMargerethe</test>
NOTE: I wish to have it working without
for-each
loop.
you can try using
apply-templates
directly on the<name>
element: