Мне нужно посчитать количество узлов из выходного файла. Я выполняю некоторые манипуляции с данными (создаю новую структуру из узлов), как вы можете видеть ниже:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes" method="xml"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:strip-space elements="*"/>
<xsl:template match="resources">
<xsl:param name="pIndex" select="0"/>
<xsl:variable name="vToken" select="substring-before(substring(concat(.,','), $pIndex+1), ',')"/>
<xsl:variable name="vnewIndex" select="$pIndex+string-length($vToken)+1"/>
<resource_code>
<xsl:value-of select="normalize-space($vToken)"/>
</resource_code>
<xsl:apply-templates select="self::node()[not($vnewIndex >= string-length(.))]">
<xsl:with-param name="pIndex" select="$vnewIndex"/>
</xsl:apply-templates>
</xsl:template>
Мой входной файл выглядит так:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<resources>
<resource_code>Truck, Van</resource_code>
</resources>
</root>
Код xsl, показанный выше, возвращает мне, что:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<resources>
<resource_code>Truck</resource_code>
<resource_code>Van</resource_code>
</resources>
</root>
И я хочу посчитать количество тегов в моем выходном файле, например:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<resources>
<resource_code>Truck</resource_code>
<resource_code>Van</resource_code>
</resources>
<nofresources>2</nofresources>
</root>
Как я мог это сделать? Я использую xslt 1.0!