RE: [xsl] Length of a literal string containing embedded tags

Subject: RE: [xsl] Length of a literal string containing embedded tags
From: "Darren Wheatley" <darren@xxxxxxxxxxxx>
Date: Wed, 1 Aug 2007 14:44:58 +0100

Thanks for the reply (and thanks to everyone else who posted as well).

I'll give that a go now!



-----Original Message-----
From: Abel Braaksma [] 
Sent: 01 August 2007 14:21
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Length of a literal string containing embedded tags

Abel Braaksma wrote:
>   1. if you do not care about whitespace, CDATA and empty tags like in 
> MK's example above, you can use the information from the infoset to 
> calculate the length of the node you are having by using name() and
> attribute() methods (and perhaps namespace methods) and some 
> string-length addition.

That would be (for the fun of it), something alongside the following 
(assuming the context node must be counted):

string-length(name()), 5),
string-length(), 4),
string-length(), 4),
    descendant-or-self::comment()/(string-length(), 7)

And yes, the double parentheses around sum() are on purpose ;)

Note that the last one in each selection is the minimal number of extra 
characters that are used in literal XML, i.e., for an attribute it 
requires two quotes, one whitespace (at least) and one equal sign, 
totaling 4.

Note also that this XPath expression sees all elements as 
<elem>data</elem>, all texts as normal texts (no cdata, each entity as 
one), all whitespace as relevant and cannot count markup-whitespace etc.

-- Abel Braaksma

Current Thread