xsl-list
[Top] [All Lists]

Re: unparsed-text and for-each-group

2005-12-21 11:04:59
On 12/21/05, David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:
only one unparsed-text to pull in the whole file then  use regular
expressions, probably easiset to pu every lin ein an l first

<xsl:variable name="lines" as="element()*"">
<xsl:for-each select="tokenize(unparsed-text('file.txt','&#13;?&#10;')">
 <l><xsl:value-of select="."/>
</xsl:for-each>
</xsl:element>

Ok, doing this part rightly got me a <poem> with lots of <l> elements
in it... but when I try to expand it to do the second part...
then use for-each-group to group up the versesinto lg elements based on
empty l elements.

I'm obviously not uisng $lines right nor testing for 'empty' (i.e.
having whitespace) <l> elements correctly.  The way I was trying was:
--------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:param name="input" />
<xsl:param name="output" />
<xsl:variable name="source1" select="$input"/>
<xsl:variable name="output1" select="$output"/>
<xsl:variable name="encoding" select="'iso-8859-1'"/>
<xsl:variable name="lines" as="element()*">
<xsl:for-each select="tokenize(unparsed-text($source1, $encoding),
'&#13;?&#10;')">
                        <l><xsl:value-of select="."/></l>
</xsl:for-each>
</xsl:variable>

        <xsl:template name="main">
<xsl:result-document href = "{$output1}">
<poem>  
<title><xsl:value-of select="$lines/l[1]"/></title>
<xsl:if test="not(normalize-space($lines/l[2])='
')"><author><xsl:value-of select="$lines/l[2]"/></author></xsl:if>
<xsl:for-each-group select="$lines/l[position >2]"
group-starting-with="l[normalize-space(.)=' ']">
        <lg>
                <xsl:copy-of select="current-group()"/>
        </lg>
        </xsl:for-each-group>
</poem>
</xsl:result-document>
</xsl:template>

</xsl:stylesheet>
--------

I hear mince pies calling....

-james
--
James Cummings, Cummings dot James at GMail dot com
<Prev in Thread] Current Thread [Next in Thread>