You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Dave Brondsema <da...@brondsema.net> on 2003/07/17 16:28:08 UTC
text2document
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,
--
Dave Brondsema
dave@brondsema.net
http://www.brondsema.net - personal
http://www.splike.com - programming
Re: text2document
Posted by Dave Brondsema <da...@brondsema.net>.
Any plaintext file will work. The is added at the end of each line, it is
not in the source file.
Thanks!
Quoting Juan Jose Pablos <ch...@che-che.com>:
> Dave,
>
> I will have a look.. have you got a test.txt this stuff?
>
> Make sure it got the ' ', so I can see the error as well..
>
>
> Cheers
>
> Cheche
>
>
>
> Dave Brondsema wrote:
> > Quoting Dave Brondsema <da...@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 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="' '"/>
> > <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>
>
Re: text2document
Posted by Juan Jose Pablos <ch...@che-che.com>.
Dave,
I will have a look.. have you got a test.txt this stuff?
Make sure it got the ' ', so I can see the error as well..
Cheers
Cheche
Dave Brondsema wrote:
> Quoting Dave Brondsema <da...@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 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="' '"/>
> <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>
Re: text2document
Posted by Dave Brondsema <da...@brondsema.net>.
Quoting Dave Brondsema <da...@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>