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 |
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: [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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Length of a literal strin, Abel Braaksma | Thread | Re: [xsl] Length of a literal strin, G. Ken Holman |
[xsl] Finding the current node type, Mark Anderson | Date | Re: [xsl] Finding the current node , Abel Braaksma |
Month |