[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Length of a literal string containing embedded tag

Subject: RE: Length of a literal string containing embedded tags
From: "Darren Wheatley" <darren@xxxxxxxxxxxx>
Date: Wed, 1 Aug 2007 14:44:58 +0100
RE:  Length of a literal string containing embedded tag
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.online@xxxxxxxxx] 
Sent: 01 August 2007 14:21
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.