This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Formating to text
- To: xsl-list at mulberrytech dot com
- Subject: Formating to text
- From: Eric van der Vlist <vdv at dyomedea dot com>
- Date: Fri, 24 Mar 2000 00:12:33 +0100
- Reply-To: xsl-list at mulberrytech dot com
Hi,
I am trying to find a simple solution to format a XML document
(XMLNews-Story) to raw text while preserving some presentation such as
paragraphs, lists and indentation.
Taking this snippet :
<p> this is a list :
<li>item 1</li>
<li>item 2</li>
end of the
list
<ul>indentation
</ul>
</p>
as an example, it's possible to transform (I attach the XSLT below) this
into something which is describing the raw presentation of the words and
blocs of words such as :
<?xml version="1.0" encoding="utf-8"?>
<b indent="0" cr="1">
<w value="this"/>
<w value="is"/>
<w value="a"/>
<w value="list"/>
<w value=":"/>
<b indent="0" cr="1">
<w value="."/>
<b ident="1" cr="0">
<w value="item"/>
<w value="1"/>
</b>
</b>
<b indent="0" cr="1">
<w value="."/>
<b indent="1" cr="0">
<w value="item"/>
<w value="2"/>
</b>
</b>
<w value="end"/>
<w value="of"/>
<w value="the"/>
<w value="list"/>
<b indent="1" cr="1">
<w value="indentation"/>
</b>
</b>
where b is a bloc with attributes indent (value of the indentation) and
cr (do we have to go to the next line) and w is a word.
This structure is reflecting pretty well the layout of the text, but
from there I don't see how I can go on with XSL...
I am using XT and can write an output handler to deal with it, but I
would like to be sure I cannot proceed using XSLT only !
Does anyone have any idea ?
Thanks
Eric
--------------- XSLT ---------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="text()" name="text">
<xsl:param name="string" select="normalize-space(.)"/>
<xsl:variable name="before" select="substring-before($string, ' ')"/>
<xsl:variable name="after" select="substring-after($string, ' ')"/>
<xsl:choose>
<xsl:when test="$before!=''">
<w value="{$before}"/>
<xsl:call-template name="text">
<xsl:with-param name="string" select="$after"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$string!=''">
<w value="{$string}"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="p">
<b ident="0" cr="1">
<xsl:apply-templates select="@*|node()"/>
</b>
</xsl:template>
<xsl:template match="ul">
<b indent="1" cr="1">
<xsl:apply-templates select="@*|node()"/>
</b>
</xsl:template>
<xsl:template match="li">
<b indent="0" cr="1"><w value="."/>
<b indent="1" cr="0">
<xsl:apply-templates select="@*|node()"/>
</b>
</b>
</xsl:template>
</xsl:stylesheet>
--
------------------------------------------------------------------------
Eric van der Vlist Dyomedea
http://xmlfr.org http://ducotede.com http://dyomedea.com
------------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list