Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] force
after x words | automate xsl |

From: Martin Honnen <Martin.Honnen@---.-->
To: xsl-list@-----.------------.---
Date: 8/1/2009 2:13:00 PM
j milo taylor wrote:
> if i have for example
> 
> <work_notes>
> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
> veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
> commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 
> velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 
> occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
> mollit anim id est laborum.
> </work_notes>
> 
> is there a way i can force a </br> after a certain number of words in 
> each line? in a xslt? (Netbeans)

Netbeans is Java, isn't it? So you could use Saxon 9 and XSLT 2.0:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   exclude-result-prefixes="xs"
   version="2.0">

   <xsl:output method="html" indent="yes"/>
   <xsl:param name="x" select="5"/>


   <xsl:template match="work_notes">
     <div>
       <xsl:for-each-group select="tokenize(normalize-space(), '\s+')" 
group-by="(position() - 1) idiv $x">
         <xsl:value-of select="current-group()"/>
         <br />
       </xsl:for-each-group>
     </div>
   </xsl:template>

</xsl:stylesheet>

Output is

<div>Lorem ipsum dolor sit amet,<br>consectetur adipisicing elit, sed 
do<br>eiusmod tempor incididunt ut labore<br>et dolore magna aliqua. 
Ut<br>enim ad minim veniam, quis<br>nostrud exercitation ullamco laboris 
nisi<br>ut aliquip ex ea commodo<br>consequat. Duis aute irure 
dolor<br>in reprehenderit in voluptate velit<br>esse cillum dolore eu 
fugiat<br>nulla pariatur. Excepteur sint occaecat<br>cupidatat non 
proident, sunt in<br>culpa qui officia deserunt mollit<br>anim id est 
laborum.<br></div>


-- 

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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@l...>
--~--



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