Subject: Re: [xsl] Line break algorithm From: "Rick Quatro rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 3 May 2020 15:23:55 -0000 |
Thank you Michael. This is my first use of xsl:iterate and very useful in understanding how it works. Here is my finished test stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:rq="http://www.frameexpert.com" exclude-result-prefixes="xs rq" version="3.0" expand-text="yes"> <xsl:output indent="yes"/> <xsl:param name="line" select="'Acceptable HAZMAT Items - Carry-On Or Checked Bags - Passenger and Cargo Flights'"/> <xsl:template name="xsl:initial-template"> <xsl:message select="''"/> <line> <xsl:call-template name="line"> <xsl:with-param name="input" select="$line"/> <xsl:with-param name="break-count" select="34" as="xs:integer"/> </xsl:call-template> </line> </xsl:template> <xsl:template name="line"> <xsl:param name="input"/> <xsl:param name="break-count" as="xs:integer"/> <xsl:iterate select="tokenize($input)"> <xsl:param name="line-length" select="0"/> <xsl:param name="break-count" select="$break-count"/> <xsl:message select="position()=last()"></xsl:message> <xsl:choose> <xsl:when test="$line-length gt $break-count"> <break/> <xsl:value-of select="concat(.,if(position()!=last()) then ' ' else '')"/> <xsl:next-iteration> <xsl:with-param name="line-length" select="string-length(.) + 1"/> <xsl:with-param name="break-count" select="$break-count - 5"/> </xsl:next-iteration> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(.,if(position()!=last()) then ' ' else '')"/> <xsl:next-iteration> <xsl:with-param name="line-length" select="$line-length + string-length(.) + 1"/> <xsl:with-param name="break-count" select="$break-count"/> </xsl:next-iteration> </xsl:otherwise> </xsl:choose> </xsl:iterate> </xsl:template> </xsl:stylesheet> which gives me this: <?xml version="1.0" encoding="UTF-8"?> <line>Acceptable HAZMAT Items - Carry-On <break/>Or Checked Bags - Passenger and <break/>Cargo Flights</line> Thanks again! -Rick
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Line break algorithm, Michael Kay mike@xxx | Thread | Re: [xsl] Line break algorithm, Terry Badger terry_b |
Re: [xsl] Joining list fragments, Imsieke, Gerrit, le- | Date | [xsl] Find the next item in a seque, Rick Quatro rick@xxx |
Month |