xsl-list
[Top] [All Lists]

Re: [xsl] how to break <preformat> into <p>

2015-03-23 09:42:48
Hi,

Of course, when you have

<proformat>Line 1
Line 2 <b>ends in bold
Line 3 in bold</b>
Line 4
</preformat>

... things get more interesting. (It's an overlap problem. :-)

For this, you need generic tree-splitting logic like what you see here:

https://github.com/wendellpiez/MITH_XSLT/blob/master/xslt/p-promote.xsl

In your case, I'd run a first pass as Gerrit suggests (a
micropipeline), to get <linebreak/> elements to use, then do something
like this.

Cheers, Wendell


On Mon, Mar 23, 2015 at 7:06 AM, Imsieke, Gerrit, le-tex
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
wrote:
You may transform it in two passes:

1. Create a programlisting with <linebreak/> elements, using only the
matching-substring instruction in analyze-string. Store it in a variable.

2. Transform the variable’s children using
for-each-group/@group-ending-with='linebreak' (or @group-starting-with).

Caveat: Make sure that you declare the variable
as="element(programlisting)"; if you omit the as="…" attribute, you will
get a document node containing a programlisting element. Selecting
$variable/node() will yield different elements for both cases:
programlisting/node() if the as="…" attribute is present, programlisting
if it isn’t.

Gerrit

On 23.03.2015 11:54, Joga Singh Rawat jrawat(_at_)aptaracorp(_dot_)com wrote:
Hi Guys,
We need a clue to break <preformat> into multiple paragraph. Using below xsl
we are not able to transform <bold>

Input
<preformat>
Line 1
Line <bold>2</bold>
Line 3
</preformat>

Required output
<programlisting>
<p>Line 1</p>
<p>Line <b>2</b></p>
<p>Line 3</p>
</programlisting>

XSL
<xsl:template match="preformat">
<programlisting>
 <xsl:for-each-group select="." regex="[\n\r]">
  <xsl:non-matching-substring>
   <p><xsl:value-of select="."/></p>
  </xsl:non-matching-substring>
 </xsl:for-each-group>
</programlisting>

Thanks in advance
...JSR



--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vöckler




-- 
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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