xsl-list
[Top] [All Lists]

[xsl] Breaking up Program Code Examples

2012-09-18 14:34:09
Hello,

We are having issues with copying and pasting programming code examples in our 
documentation. 
The documentation has coding examples and our users want to copy these lines of 
code and paste 
them in their applications in order to run them. The newlines in the code, 
we're outputting in
as-is mode, were being lost so Antenna House suggested that we place <fo:block> 
elements 
around each line of code. Outputting each line in its own block will hopefully 
eliminate the
problem.

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. 

Here is the example of the tokenize:

<fo:block xsl:use-attribute-sets="code" space-before="6pt" space-after="0pt" 
    white-space="pre" white-space-treatment="preserve" 
linefeed-treatment="preserve">
  <xsl:for-each select="tokenize(., '\n')">
    <fo:block><xsl:sequence select="."/></fo:block>
  </xsl:for-each> 
</fo:block>

Here is an example of the XML:
<codeBlock eid="n0b7p8f53ujhsbn17928o22t9lyb">
<code eid="p01xqdrm89zmnon115yg9qm064mb">begin;
  x=y+<userSuppliedValue>2</userSuppliedValue>;
end;</code>
</codeBlock>

The <userSuppliedValue> element italizes the code it contains but 
since it's getting eaten by tokenize what we get is:

begin;
x=y+2;
end;

Thanks for any suggestions on how to get this working.

Craig

--------------------------------------------------------------------
Craig R. Sampson    SAS Institute Inc.  email: 
craig(_dot_)sampson(_at_)sas(_dot_)com
  XML Technologies  SAS Campus Drive    phone: (919) 531-7417
                    Cary, NC.  27513    FAX:   (919) 677-4444
--------------------------------------------------------------------
     Please consider the environment before printing this email




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