Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Abel Braaksma <abel.online@--------->
To:
Date: 8/1/2007 1:22:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent