xslt: force a start character on every output line

Discussion in 'XML' started by danmc91, Oct 18, 2005.

  1. danmc91

    danmc91 Guest

    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
    danmc91, Oct 18, 2005
    #1
    1. Advertising

  2. "danmc91" <> writes:

    > 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.
    Alain Ketterlin, Oct 18, 2005
    #2
    1. Advertising

  3. danmc91

    Peter Flynn Guest

    danmc91 wrote:

    >
    > 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
    Peter Flynn, Oct 18, 2005
    #3
  4. danmc91

    danmc91 Guest

    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
    danmc91, Oct 19, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gnarlodious
    Replies:
    9
    Views:
    13,369
    Bernhard Sturm
    Jan 28, 2005
  2. Markus Wiedenmaier

    XSLT: Output of character references

    Markus Wiedenmaier, May 21, 2004, in forum: XML
    Replies:
    2
    Views:
    482
    Janwillem Borleffs
    May 21, 2004
  3. =?Utf-8?B?SXJ3YW5zeWFo?=
    Replies:
    4
    Views:
    2,440
    =?Utf-8?B?SXJ3YW5zeWFo?=
    Oct 30, 2007
  4. albert kao
    Replies:
    3
    Views:
    1,984
    Arne Vajhøj
    Feb 2, 2011
  5. bernadou

    Force multi line field value to output with line breaks?

    bernadou, Jan 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    345
    bernadou
    Jan 23, 2006
Loading...

Share This Page