How can i disply the same level element values after if conditon
For example
XML
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
XSLT
<xsl:if test="/catalog/cd/country='UK'">
<xsl:value-of select="title"/>
<xsl:value-of select="artist"/>
</xsl:if>
This will not displying the title and artist of UK level elements
I know that one way of solving it is to use for each loop but i am looking for an efficient method
This can be done using only templates:
There are many other ways — depending on your requirements, of course — to arrange templates to generate your desired output. For example, you might end up with explicit templates for handling
titleandartistelements (or for explicitly hiding all other children of eachcd).All of this depends on your particular needs, but the general point I wanted to show here is that you gain a lot of power (and end up with cleaner code) when you properly catch target elements in a template match (instead of ad-hoc conditionals).