xslt: force a start character on every output line

D

danmc91

Hi,

I'm just getting going with xml and xslt. I'm trying to write what are
essentially man pages and I need 3 output formats.

1) nroff -man format for real man pages

2) html for an online help browser

3) ascii where every line must start with a '%' character (octave
online help).

So, I made a simple DTD, a simple man page in xml format and hacked up
some .xsl files.

I've more or less got something working for #1 and #2. The .xsl file
for #3 is proving to be a real pain. I'm using <xsl:eek:utput
method="text"/>. Is there some way to force every line in the output
file to start with a %? Or maybe I'm doing this the wrong way.
Perhaps I should output html and use something like

xsltproc foo.xsl bar.xml | lynx -dump - | awk '{printf("% %s\n",
$0)}' > bar.m

Any comments? Is this the sort of thing that xml and xslt are meant
for or am I really using the Wrong Tool?

Thanks
-Dan
 
A

Alain Ketterlin

danmc91 said:
3) ascii where every line must start with a '%' character (octave
online help).
I've more or less got something working for #1 and #2. The .xsl file
for #3 is proving to be a real pain. I'm using <xsl:eek:utput
method="text"/>. Is there some way to force every line in the output
file to start with a %?

I had to do this recently, and decided to output text with one long
line per paragraph (or so), then use fmt[*] to properly reformat
something that had to be kept in the 80-column limit.
xsltproc foo.xsl bar.xml | lynx -dump - | awk '{printf("% %s\n",
$0)}' > bar.m

If your only problem is to prepend '% ' to all lines, you could use :

xsltproc ... | sed 's/^/% /'

-- Alain.

[*] : weel, not really fmt, but a self-maid tool whose only purpose
was to properly reformat some parts of the document.
 
P

Peter Flynn

danmc91 said:
Hi,

I'm just getting going with xml and xslt. I'm trying to write what are
essentially man pages and I need 3 output formats.

1) nroff -man format for real man pages

2) html for an online help browser

3) ascii where every line must start with a '%' character (octave
online help).

So, I made a simple DTD, a simple man page in xml format and hacked up
some .xsl files.

I've more or less got something working for #1 and #2. The .xsl file
for #3 is proving to be a real pain.

The assumption in most projects like this is that the output from
XML-->XSLT will be postprocessed by a formatter. This is true in
(1) nroff and (2) browser, but false for (3) because (my understanding
is that) Octave requires preformatted text -- in other words something
else has to do the formatting.
I'm using <xsl:eek:utput
method="text"/>. Is there some way to force every line in the output
file to start with a %? Or maybe I'm doing this the wrong way.
Perhaps I should output html and use something like

xsltproc foo.xsl bar.xml | lynx -dump - | awk '{printf("% %s\n",
$0)}' > bar.m

Any comments? Is this the sort of thing that xml and xslt are meant
for or am I really using the Wrong Tool?

You are absolutely right to be using XML to store the document, and to
use XSLT to output it to other formats for (1) and (2). Your solution
to (3) is one good way to do it. Alain posted another.

I suspect you *could* do it in XSLT, by buffering the output and slicing
it at (eg) 65 characters, but it would be a pain to code.

If you wanted to make a better shot at smoothing out the ragged right
margin caused by Octave using a proportional font to display text which
Lynx had formatted on the basis of a monospace font, I guess you could
output LaTeX and dvi2tty, but that has severe problems with anything
other than the 95 printable characters of ASCII.

///Peter
 
D

danmc91

ok. Thanks for the replies. I think what I'll do for #3 is to
generate html then

x3m -dump foo.html | awk '{print "% " $0}' > foo.m

That seems to work well, and as you point out nroff and html viewers
both fill the roll of formatting the data for viewing.

Now I just need to get more proficient in xslt programming. Seems like
there are many ways to get to the same answer but some may be much
cleaner than others. I have something working but boy do I feel like
there are a lot of details I don't quite understand.

-Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,250
Members
46,848
Latest member
Graciela Mitchell

Latest Threads

Top