Flag
Flag

Reputation: 577

XSLT - checking the total size of //text()

I'm trying to get all the text of an XML file as one node instead of a sequence of nodes in order to check the size of the whole text.

XML

<root>
 <a>a word</a>
 <b>Some text <c>in</c> the file</b>
</root>

XSL

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:variable name="$text" select="/root/descendant-or-self::*/text()" />
    <xsl:message select="string-length($text)"/>
  </xsl:template>
</xsl:stylesheet>

This does not work as I get a sequence in $text instead of a simple string.

How can I do this?

Upvotes: 0

Views: 914

Answers (1)

hr_117
hr_117

Reputation: 9627

Try this XSLT 1.0

<xsl:template match="/">
  <xsl:variable name="text" select="string(.)" />
  <xsl:message>
    <xsl:value-of select="string-length($text)"/>
  </xsl:message>
</xsl:template>

Upvotes: 1

Related Questions