xsl-list
[Top] [All Lists]

Re: [xsl] Breaking up Program Code Examples

2012-09-18 15:56:52
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(_at_)mentea(_dot_)net
Consultant                                 http://www.mentea.net
Mentea       13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
 --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    XML, XSL-FO and XSLT consulting, training and programming


--~------------------------------------------------------------------
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>