Вот XPath один вкладыш :
string-length(/) - string-length(translate(string(/), $vNL, ''))
Это оценивает общее количество символов NL в конкатенации всех текстовых узлов в документе XML.
Объяснение:
translate(string(/), $vNL, '')
производит из строкового значения узла документа (конкатенации всех текстовых узлов в документе XML) другой строка, в которой любой NL характер был заменен на пустой строке (удален).
Затем, вычитая это из общей длины строки, дает нам точно количество (удаленных) символов NL.
Вот полный пример кода:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="vNL" select="'
'"/>
<xsl:template match="/">
<xsl:value-of select=
"string-length(/)
- string-length(translate(string(/), $vNL, ''))
"/>
</xsl:template>
</xsl:stylesheet>
когда это преобразование применяется на следующий документ XML:
<text>
Dec. 13 — As always for a presidential inaugural, security and surveillance were
extremely tight in Washington, DC, last January. But as George W. Bush prepared to
take the oath of office, security planners installed an extra layer of protection: a
prototype software system to detect a biological attack. The U.S. Department of
Defense, together with regional health and emergency-planning agencies, distributed
a special patient-query sheet to military clinics, civilian hospitals and even aid
stations along the parade route and at the inaugural balls. Software quickly
analyzed complaints of seven key symptoms — from rashes to sore throats — for
patterns that might indicate the early stages of a bio-attack. There was a brief
scare: the system noticed a surge in flulike symptoms at military clinics.
Thankfully, tests confirmed it was just that — the flu.
</text>
разыскиваемого, правильный результат получается:
12
"этот код" какой код? –
Вы хотите просто подсчитать количество раз, когда «val_cr_ln» встречается в документе XML? –