linebreaks and indents in TEXT output
Posted: Thu Sep 10, 2020 1:30 am
I have a DITA document for **TEXT** output that contains msg elements like this:
I need the output of msgText to break at each <?linebreak?> and to indent the result. Because the output is simple text my hands are tied in a lot of ways. Here’s a sample of the desired output:
-----------------------------------------------------------------
1234567 The variations of this message are explained below.
-option one.
-option two.
I’ve managed to force the line breaks and indent the subsequent lines, BUT where any segment of msgText is long enough to wrap to the next line, the wrapped portion is not indented…
-----------------------------------------------------------------
1234567 The variations of this message are explained below. This
part wraps and needs to be indented.
-option one. When these segments are long enough to wrap
this part wraps and needs to be indented.
-option two.
Here’s the code I have that makes it work to the extent it does:
I’m close to the solution on this, but I can’t think of a way to directly manipulate the segments of msgText since I’m breaking it into segments when the focus is on <?linebreak?>.
Any thoughts, ideas, lifelines gratefully accepted. Thanks!
Code: Select all
<msg>
<msgId>
<msgNumber>1234567</msgNumber>
</msgId>
<msgText>The variations of this message are explained below. <?linebreak?> -option one. <?linebreak?> -option two.
</msgText>
</msg>
-----------------------------------------------------------------
1234567 The variations of this message are explained below.
-option one.
-option two.
I’ve managed to force the line breaks and indent the subsequent lines, BUT where any segment of msgText is long enough to wrap to the next line, the wrapped portion is not indented…
-----------------------------------------------------------------
1234567 The variations of this message are explained below. This
part wraps and needs to be indented.
-option one. When these segments are long enough to wrap
this part wraps and needs to be indented.
-option two.
Here’s the code I have that makes it work to the extent it does:
Code: Select all
<xsl:template match="*[contains(@class, ' msg/msgText ')]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="processing-instruction()[name() = 'linebreak']">
<!-- This forces a linebreak by filling an entire line with non-breaking-spaces, and tacking on
a normal space to allow content that follows to wrap to the next line. -->
<text>
<xsl:for-each select="1 to $LINELENGTH"> </xsl:for-each>
<xsl:text> </xsl:text>
</text>
<!-- This indents the first line of the next segment of msgText. -->
<text>       </text>
</xsl:template>
Any thoughts, ideas, lifelines gratefully accepted. Thanks!