Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Implementing a "State Machine" in XSL? [Thread Next] Re: Implementing a "State Machine" in XSL?To: NULL Date: 2/11/2008 9:28:00 PM Oleg Tkachenko schrieb: > That's trivial in XSLT 2.0 and a bit cumbersome in pure XSLT 1.0. As always in life, i of course only have XSLT 1.0 (Sharepoint 2007) :-) > One idea is to traverse the tree in document order and checking if > current element would exceed max length. If it would not then output it > and move to the next one. If it would, process this node children > recursively. If you come down to a text node that's too long, split it. > > Here is a sketch implementation. It's far from perfect, but you get the > idea. Thank you! I'll look at that. > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:param name="max-len" select="15"/> > > <xsl:template match="/"> > <xsl:call-template name="output"> > <xsl:with-param name="nodes" select="*"/> > </xsl:call-template> > </xsl:template> > > <xsl:template name="output"> > <xsl:param name="running-length" select="0"/> > <xsl:param name="nodes" select="/.."/> > > <xsl:choose> > <xsl:when test="string-length($nodes[1]) + $running-length <= > $max-len"> > <xsl:copy-of select="$nodes[1]"/> > <xsl:if test="$nodes[2]"> > <xsl:call-template name="output"> > <xsl:with-param name="running-length" > select="string-length($nodes[1]) + $running-length"/> > <xsl:with-param name="nodes" select="$nodes[position() != > 1]|$nodes[1]/*"/> > </xsl:call-template> > </xsl:if> > </xsl:when> > <xsl:when test="$nodes[1]/self::text()"> > <xsl:value-of select="substring($nodes[1], 1, $max-len - > $running-length)"/> > </xsl:when> > <xsl:otherwise> > <xsl:if test="$nodes[1]/node()"> > <xsl:element name="{name($nodes[1])}" > namespace="{namespace-uri($nodes[1])}"> > <xsl:copy-of select="$nodes[1]/@*"/> > <xsl:call-template name="output"> > <xsl:with-param name="running-length" > select="$running-length"/> > <xsl:with-param name="nodes" select="$nodes[1]/node()"/> > </xsl:call-template> > </xsl:element> > </xsl:if> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > </xsl:stylesheet> > > -- http://www.Stum.de · http://www.Souvenance.net e-Mail Adresse ist gültig, wird aber äußerst selten gelesen. e-Mail address is valid, but read very infrequently. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
