[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Count words and add line-brake
> I hope someone can help. I would like to do the following. > > 1. Count the words in a specific xml node. > 2. Insert a line-brake after every 15th word. > > Source: > <txt>Here is some text. Here is some text. Here is some text. > Here is some text. Here is some text.Here is some text. Here > is some text. Here is some text. Here is some text. Here is > some text.</txt> > > > Output: > <txt> > Here is some text. Here is some text. Here is some text. > Here is some <br /> > text. Here is some text. Here is some text. Here is some > text. Here is <br /> > some text. Here is some text. Here is some text. > </txt> I would suggest using XSLT 2.0 or XSLT 1.0 + tokenize extension function to do this, then you write something like the following: <xsl:template match="txt"> <txt> <xsl:for-each select="tokenize(.,'\s')"> <xsl:copy-of select="."/> <xsl:if test="position() mod 15 = 0"><br /></xsl:if> </xsl:for-each> ... If you are using XSLT 1.0 + extensions then the tokenize funtion would need be in the processors namespace (for example saxon:tokenize(...)) I'm sure there's a few gotchas with using the \s character class for this task, but I (still) don't know regexs well enough to come upu with anything better. cheers andrew
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|