xsl-list
[Top] [All Lists]

Re: [xsl] Open Office Multi-Line Normalization

2007-04-18 17:37:36
On Wed, 18 Apr 2007 18:16:50 -0400
Michael B Allen <mba2000(_at_)ioplex(_dot_)com> wrote:

On Wed, 18 Apr 2007 23:03:44 +0100
David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:


looks like you just want

<pre>
<xsl:apply-templates/>
</pre>

the default element and text node templates will do the rest for you,

Hi David,

Ok, but there's no outer tag to match on. I failed to mention that there
are many of these "pre" sequences. If I can isolate each set then I can
use the template you suggest.

This below seems to work but of course I'd be interested in improvements.

Basically this finds the p node with an immediately preceding sibling
that does not have the p_5f_prototype style. That's the first element
in the sequence. Then it finds the first p node after that one that does
not have the p_5f_prototype style. That's the node right after the last
element in the sequence. Then I just use [. << $end] to isolate the set.

<xsl:template match="text:p[(_at_)text:style-name='p_5f_prototype' and 
not(preceding-sibling::*[1][(_at_)text:style-name='p_5f_prototype'])]">
    <xsl:variable name="end" 
select="following-sibling::*[not(@text:style-name='p_5f_prototype')][1]"/>
    <pre>   
        <xsl:apply-templates mode="prototype" select=".|following-sibling::*[. 
&lt;&lt; $end]"/>
    </pre><xsl:text>
</xsl:text>
</xsl:template>
     
<xsl:template mode="prototype" match="text:s">
    <xsl:value-of select="substring('                     ', 1, @text:c)"/>
</xsl:template>
     
<xsl:template mode="prototype" match="text()|@*">
    <xsl:value-of select="."/><xsl:text>
</xsl:text>
</xsl:template>

The only wart is that an empty element does not produce a blank line
because I guess the empty element doesn't match 'text()'. Meaning the
following:

  <text:p text:style-name="p_5f_prototype">require_once('foo.php');</text:p>
  <text:p text:style-name="p_5f_prototype"/>
  <text:p text:style-name="p_5f_prototype">bool ...

yields:

  require_once('plexcel.php');
  bool ...

whereas I would like:

  require_once('plexcel.php');
  
  bool ...

Mike

-- 
Michael B Allen
PHP Active Directory Kerberos SSO
http://www.ioplex.com/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>