sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
danmc91's Avatar

xslt: force a start character on every output line


Question posted by: danmc91 (Guest) on October 18th, 2005 03:55 AM

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:output
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

3 Answers Posted
Alain Ketterlin's Avatar
Alain Ketterlin October 18th, 2005 02:25 PM
Guest - n/a Posts
#2: Re: xslt: force a start character on every output line

"danmc91" <spam@mcmahill.net> writes:
[color=blue]
> 3) ascii where every line must start with a '%' character (octave
> online help).[/color]
[color=blue]
> 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:output
> method="text"/>. Is there some way to force every line in the output
> file to start with a %?[/color]

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.
[color=blue]
> xsltproc foo.xsl bar.xml | lynx -dump - | awk '{printf("% %s\n",
> $0)}' > bar.m[/color]

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.
Peter Flynn's Avatar
Guest - n/a Posts
#3: Re: xslt: force a start character on every output line

danmc91 wrote:
[color=blue]
>
> 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.[/color]

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.
[color=blue]
> I'm using <xsl:output
> 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?[/color]

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

danmc91's Avatar
Guest - n/a Posts
#4: Re: xslt: force a start character on every output line

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

 
Not the answer you were looking for? Post your question . . .
196,801 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,801 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors