forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juan Jose Pablos <che...@che-che.com>
Subject Re: text2document
Date Thu, 17 Jul 2003 21:12:05 GMT
Dave,

I will have a look.. have you got a test.txt this stuff?

Make sure it got the '&#13;', so I can see the error as well..


Cheers

Cheche



Dave Brondsema wrote:
> Quoting Dave Brondsema <dave@brondsema.net>:
> 
> 
>>I would like to put some .txt files in the xdocs directory and have them
>>generate documents where the content is all the text within a <source> tag.

>>This seems like it would be easy to implement, but I'm not very familiar with
>>forrest's pipelines.  Anyone up for it?
>>
>>TIA,
>>
> 
> 
> Well.. I did it myself.  It's not pretty how it takes care of line endings, but
> it works.  If someone knows how to fix it that'd be great.
> 
> To implement this, use the attached files and add the following to forrest.xmap
> in the source formats section:
>           <map:when test="content/xdocs/{1}.txt">
>             <map:match type="regexp" pattern="^(.*?)([^/]*).xml$">
>               <map:generate type="text2xml" src="content/xdocs/{1}{2}.txt" />
>               <map:transform type="lexer"   src="resources/grammars/text.xlex"/>
>               <map:transform type="parser"  src="resources/grammars/text.xgrm"/>
>               <map:transform src="resources/stylesheets/text2document.xsl">
>                 <map:parameter name="name" value="{2}" />
>               </map:transform>
>               <map:transform type="idgen" />
>               <map:serialize type="xml"/>
>             </map:match>
>           </map:when>
> 
> 
> ------------------------------------------------------------------------
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
>                 xmlns:st="http://chaperon.sourceforge.net/schema/syntaxtree/1.0"
>                 exclude-result-prefixes="st">
> 
>  <xsl:output indent="yes" 
>              method="html"
>              doctype-public="-//APACHE//DTD Documentation V1.1//EN"
>              doctype-system="document-v11.dtd"
>              cdata-section-elements="source"/>
> 
>  <xsl:param name="name"/>
> 
>  <xsl:template match="st:document">
>   <document>
>    <header>
>      <title>
>        <xsl:value-of select="$name"/>
>      </title>
>    </header>
>    <body>
>     <source>
>       <!--<xsl:value-of select="st:text/text()"/>-->
> 	  <!-- don't know why there are &#13; characters in the text, but we've got to
get rid of them -->
> 	  <xsl:call-template name="replace">
> 		 <xsl:with-param name="search" select="st:text/text()"/>
> 		 <xsl:with-param name="find" select="'&#13;'"/>
> 		 <xsl:with-param name="replace" select="''"/>
> 	  </xsl:call-template>
> 	</source>
>    </body>
>   </document>
>  </xsl:template>
>  
>  <xsl:template name="replace">
>    <xsl:param name="search"/>
>    <xsl:param name="find"/>
>    <xsl:param name="replace"/>
>    
>    <xsl:choose>
>     <xsl:when test="contains($search, $find)">
> 		<xsl:variable name="result">
> 		  <xsl:value-of select="substring-before($search, $find)"/>
> 		  <xsl:value-of select="$replace"/>
> 		  <xsl:call-template name="replace">
> 		     <xsl:with-param name="search" select="substring-after($search, $find)"/>
> 			 <xsl:with-param name="find" select="$find"/>
> 			 <xsl:with-param name="replace" select="$replace"/>
> 		  </xsl:call-template>
> 		</xsl:variable>
> 		<xsl:value-of select="$result"/>
>     </xsl:when>
> 	<xsl:otherwise>
> 		<xsl:value-of select="$search"/>
> 	</xsl:otherwise>
>    </xsl:choose>
>    
>  </xsl:template>
> </xsl:stylesheet>



Mime
View raw message