The first element titlein the document is selected :
(//title)[1]
, //title[1] title , . //title[1] title, title , , .
, :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"title[count(.|((//title)[1])) = 1]">
<PageTitle>
<xsl:apply-templates />
</PageTitle>
</xsl:template>
</xsl:stylesheet>
XML-:
<t>
<a>
<b>
<title>Page Title</title>
</b>
</a>
<b>
<title/>
</b>
<c>
<title/>
</c>
</t>
:
<t>
<a>
<b>
<PageTitle>Page Title</PageTitle>
</b>
</a>
<b>
<title />
</b>
<c>
<title />
</c>
</t>
, XPath 1.0:
$ns1 $ns2, node, $ns1, $ns2:
$ns1[count(.|$ns2) = count($ns2)]
, node -sets node, node, true(), :
count(.|$ns2) = 1
, :
title[count(.|((//title)[1])) = 1]
title .