Use this XPath one-liner:
/*/device[starts-with(., 'HTC')][1]
|
/*/device[1][not(/*/device[starts-with(., 'HTC')])]
Generally, to select node $n1
when some $condition
is true()
and to select node $n2
when this condition is false()
:
$n1[$condition] | $n2[not($condition)]
Explanation:
The above expression is the union (|
) of two sub-expressions of which only one selects a node, depending on the value of the specific $condition
.
Finally, in XSLT one will use this XPath expression like this:
<xsl:apply-templates select=
" /*/device[starts-with(., 'HTC')][1]
|
/*/device[1][not(/*/device[starts-with(., 'HTC')])]
"/>