xsl-list
[Top] [All Lists]

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

2007-08-01 06:46:53
Hi,

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

I'll give that a go now!

Cheers

D.


-----Original Message-----
From: Abel Braaksma [mailto:abel(_dot_)online(_at_)xs4all(_dot_)nl] 
Sent: 01 August 2007 14:21
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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):

sum((
    descendant-or-self::text()/(string-length()),
    descendant-or-self::element()/(string-length(name()), 
string-length(name()), 5),
    descendant-or-self::element()/attribute::*/(string-length(name()), 
string-length(), 4),
    descendant-or-self::processing-instruction()/(string-length(name()), 
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.

Cheers,
-- Abel Braaksma

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--