XSL Apply template with OR



I want to apply a template but only for the first match. Suppose I have a xml like:



<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>


Note that the second CD has no title node. and xsl:



<xsl:template match="title">
Title: <xsl:value-of select="."/><br/>
</xsl:template>

<xsl:template match="artist">
Artist: <xsl:value-of select="."/><br/>
</xsl:template>


If there is a node title I want to apply that template and otherwise I want to apply the template for artist. I'm trying something like



<xsl:apply-templates match="title | artist"/>


But there then it will use both ones, and I only want the first one to be applied. So if there is a title, use that one, otherwise use the artist. Can this be done in such a way or only by using <xsl:choose>?


No comments:

Post a Comment