Subject: Re: [xsl] Breaking up Program Code Examples From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 18 Sep 2012 16:54:17 -0400 |
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;
begin; x=y+2; end;
<?xml version="1.0" encoding="UTF-8"?> <codeBlock eid="n0b7p8f53ujhsbn17928o22t9lyb"> <code eid="p01xqdrm89zmnon115yg9qm064mb">begin; x=y +<userSuppliedValue>2</userSuppliedValue>; end;</code> </codeBlock>
Thanks for any suggestions on how to get this working.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:template match="codeBlock"> <root font-family="Times" font-size="20pt">
<layout-master-set> <simple-page-master master-name="frame" page-height="210mm" page-width="297mm" margin-top="1cm" margin-bottom="1cm" margin-left="1cm" margin-right="1cm"> <region-body region-name="frame-body"/> </simple-page-master> </layout-master-set>
<page-sequence master-reference="frame"> <flow flow-name="frame-body"> <xsl:apply-templates/> </flow> </page-sequence> </root> </xsl:template>
<xsl:template match="code"> <block white-space="pre" font-family="monospace"> <xsl:apply-templates/> </block> </xsl:template>
<xsl:template match="userSuppliedValue"> <inline font-style="italic"> <xsl:apply-templates/> </inline> </xsl:template>
-- Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012 Contact us for world-wide XML consulting and instructor-led training Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Breaking up Program Code Exam, Craig Sampson | Thread | Re: [xsl] Breaking up Program Code , Wolfgang Laun |
[xsl] Breaking up Program Code Exam, Craig Sampson | Date | Re: [xsl] Breaking up Program Code , Tony Graham |
Month |