Subject: Formatting text output handler [WAS : Re: Formating to text] From: Eric van der Vlist <vdv@xxxxxxxxxxxx> Date: Fri, 24 Mar 2000 18:25:11 +0100 |
For those who have followed this thread and are interested by the riddle, the transformation can be done by the attached stylesheet. Now, this is so verbose and slow that I wonder if writing a formatting text output handler wouldn't really be the best solution. Anyone interested by such a product (or having developed one) ? Thanks Eric PS: one could also transform to HTML and use "lynx -dump" but its wouldn't be fair, would it ? -- ------------------------------------------------------------------------ Eric van der Vlist Dyomedea http://xmlfr.org http://ducotede.com http://dyomedea.com ------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?> <b ident="0" cr="1"> <w value="this"/> <w value="is"/> <w value="a"/> <w value="list"/> <w value=":"/> <b ident="0" cr="1"> <w value="."/> <b ident="1" cr="0"> <w value="itemmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"/> <w value="1"/> </b> </b> <b ident="0" cr="1"> <w value="."/> <b ident="1" cr="0"> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="item"/> <w value="2"/> </b> </b> <w value="end"/> <w value="of"/> <w value="the"/> <w value="list"/> <b ident="1" cr="1"> <w value="indentation"/> </b> </b>
<?xml version="1.0" encoding='iso-8859-1'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xt="http://www.jclark.com/xt" > <xsl:output indent="yes" encoding="iso-8859-1" method="text"/> <xsl:template name="next"> <xsl:param name="pos"/> <xsl:param name="hpos"/> <xsl:apply-templates select="/descendant-or-self::*[position()=($pos+1)]"> <xsl:with-param name="pos" select="$pos+1"/> <xsl:with-param name="hpos" select="$hpos"/> </xsl:apply-templates> </xsl:template> <xsl:template name="spaces"> <xsl:param name="number"/> <xsl:value-of select="' '"/> <xsl:if test="$number > 1"> <xsl:call-template name="spaces"> <xsl:with-param name="number" select="$number - 1"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="line-break"> <xsl:param name="pos"/> <xsl:param name="word"/> <xsl:param name="depth"/> <xsl:value-of select="' '"/> <xsl:if test="$depth > 0"> <xsl:call-template name="spaces"> <xsl:with-param name="number" select="$depth"/> </xsl:call-template> </xsl:if> <xsl:choose> <xsl:when test="$word!=''"> <xsl:value-of select="concat($word, ' ')"/> <xsl:call-template name="next"> <xsl:with-param name="pos" select="$pos"/> <xsl:with-param name="hpos" select="$depth + string-length($word)+1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="next"> <xsl:with-param name="pos" select="$pos"/> <xsl:with-param name="hpos" select="$depth"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="*"> <xsl:param name="pos" select="1"/> <xsl:param name="hpos" select="1"/> <xsl:param name="depth" select="sum(ancestor-or-self::b/@ident)"/> <xsl:choose> <xsl:when test="@cr=1"> <xsl:call-template name="line-break"> <xsl:with-param name="pos" select="$pos"/> <xsl:with-param name="depth" select="$depth"/> </xsl:call-template> </xsl:when> <xsl:when test="@value!=''"> <xsl:choose> <xsl:when test="($depth + $hpos + string-length(@value) +1) < 75"> <xsl:value-of select="concat(@value, ' ')"/> <xsl:call-template name="next"> <xsl:with-param name="pos" select="$pos"/> <xsl:with-param name="hpos" select="$hpos + string-length(@value)+1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="line-break"> <xsl:with-param name="pos" select="$pos"/> <xsl:with-param name="depth" select="$depth"/> <xsl:with-param name="word" select="@value"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:call-template name="next"> <xsl:with-param name="pos" select="$pos"/> <xsl:with-param name="hpos" select="$hpos"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Formating to text, Eric van der Vlist | Thread | Re: Formatting text output handler , Louis-Dominique Dube |
How do I detect every other node?, Wakefield, Nicholas | Date | RE: Detecting every other node?, Wakefield, Nicholas |
Month |