Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Implementing a "State Machine" in XSL?

From: Michael Stum <devnull@----.-->
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 &lt;= 
> $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.


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