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

Subject: Re: [xsl] how to break <preformat> into <p>
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Mar 2015 14:42:32 -0000
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.imsieke@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
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 variablebs 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="b&" 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="b&" attribute is present, programlisting
> if it isnbt.
>
> Gerrit
>
> On 23.03.2015 11:54, Joga Singh Rawat jrawat@xxxxxxxxxxxxxx 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
> GeschC$ftsfC<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.imsieke@xxxxxxxxx, http://www.le-tex.de
>
> Registergericht / Commercial Register: Amtsgericht Leipzig
> Registernummer / Registration Number: HRB 24930
>
> GeschC$ftsfC<hrer: Gerrit Imsieke, Svea Jelonek,
> Thomas Schmidt, Dr. Reinhard VC6ckler
>



--
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^

Current Thread