Re: [xsl] Breaking up Program Code Examples

Subject: Re: [xsl] Breaking up Program Code Examples
From: "Tony Graham" <tgraham@xxxxxxxxxx>
Date: Tue, 18 Sep 2012 21:56:41 +0100 (IST)
On Tue, September 18, 2012 8:33 pm, Craig Sampson wrote:
...
> We are using an xsl:tokenize statement to read up until the newline
> character. This works fine
> for breaking up our code examples into individual lines but we have 2
> problems.
>
> 1) We lose indents in the code when pasted.
> 2) We allow a few embedded elements, like <userSuppliedValue>, within our
> <code> element
> that we are losing through the tokenize. We still need these to surface so
> we can react
> when they are present.
...

It's not clear to me why you're losing the line breaks.  I just copied
some text from a PDF produced by Antenna House Formatter, and the line
breaks were preserved.  The leading whitespace, however, was not
preserved, same as for you.  What output format on what platform are you
pasting from and what are you pasting into?

The properties that I used for that were:

  <fo:block
      xsl:use-attribute-sets="monospace"
      space-before="6pt"
      space-after="6pt"
      padding="6pt"
      keep-together="1"
      linefeed-treatment="preserve"
      white-space-collapse="false"
      white-space-treatment="preserve">


You could try replacing each line-end with a <fo:block/> (e.g., by using
xsl:analyze-string in a template that matches codeBlock/text()) instead of
putting each line in a fo:block.

If you want the fo:block, process the codeBlock once to insert an empty
element, e.g. that <fo:block/>, in place of each line break, then process
it again using xsl:for-each-group and use "group-starting-with" and put
the fo:block around each group (or 'current-group() except .' when the
context item is the empty element you added).

I don't think that the leading space characters are even in the PDF that I
was looking at, since I couldn't select any white-space before the text on
each line.  You may be able to get characters to copy if you replace each
space character with a no-break space character (&#xA0;), but that could
lead to problems if your users do manage to copy the no-break space
characters into their code.

Regards,


Tony Graham                                   tgraham@xxxxxxxxxx
Consultant                                 http://www.mentea.net
Mentea       13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
 --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    XML, XSL-FO and XSLT consulting, training and programming

Current Thread