[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Formating to text

Subject: Formating to text
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Fri, 24 Mar 2000 00:12:33 +0100
li formating
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.