Xslt

What's the preferred way to do XSL transformations?

Is their a reliable Ruby tool out there for the task? Or is there a fairly
standard unix tool one uses?

Thanks,
T.

On the commandline, you can use xsltproc or xalan. (I'm sure there are
others too). Both of these are apt-gettable in Debian. Xalan is from
the Apache Foundation. It's been pretty solid for a while now.

I've also seen these ruby projects floating around :slight_smile:

http://raa.ruby-lang.org/project/ruby-xslt/
http://raa.ruby-lang.org/project/libxslt/
http://raa.ruby-lang.org/project/xslt4r/

Ruby-xslt looks to have had a new version was released just recently.
You'll probably want ruby-xpath to go with it too.

The examples make it look as easy as this -

  require 'xml/xslt'

  xslt = XML::XSLT.new()
  xslt.xmlfile = "fuzface.xml"
  xslt.xslfile = "fuzface.xsl"

  out = xslt.serve()
  print out;

(This is also the libxslt-ruby package in Debian.)

I have to admit, though, that I tend to avoid XSL transformations
except in the direst of circumstances, instead using Ruby itself as my
transformation language (via the DOM, SAX, or REXML interfaces).

Just my two cents. good luck,
wad

···

On Tue, 19 Oct 2004 22:28:27 +0900, trans. (T. Onoma) <transami@runbox.com> wrote:

What's the preferred way to do XSL transformations?

Is their a reliable Ruby tool out there for the task? Or is there a fairly
standard unix tool one uses?

Thanks,
T.

trans. (T. Onoma) wrote:

What's the preferred way to do XSL transformations?

Is their a reliable Ruby tool out there for the task? Or is there a fairly standard unix tool one uses?

The last time I took a serious look at XSLT and Ruby as about a year ago. A big reason for the gap is that I've become happier doing XML transformations using REXML's pullparser, or simple regexen. But that's not to everyone's taste or choice

My recollection is that there are no complete, pure-Ruby XSLT tools.
If you require access to all the bells and whistles, you may need to use the bindings/wrappers for Sablotron or libxslt.

http://www.rubyxml.com/rubyConf2003/stateOfXmlProcessingInRuby/

will tell you what I knew a year ago. Otherwise, Google around for the libxslt or Sablotron stuff.

Or see here:

James

Nice. Thanks you for such a great reply! Very informative.

Why do you avoid XSLT? Because it is slow? Or?

Thanks,
T.

···

On Tuesday 19 October 2004 10:44 am, Will Drewry wrote:

On the commandline, you can use xsltproc or xalan. (I'm sure there are
others too). Both of these are apt-gettable in Debian. Xalan is from
the Apache Foundation. It's been pretty solid for a while now.

I've also seen these ruby projects floating around :slight_smile:

http://raa.ruby-lang.org/project/ruby-xslt/
http://raa.ruby-lang.org/project/libxslt/
http://raa.ruby-lang.org/project/xslt4r/

Ruby-xslt looks to have had a new version was released just recently.
You'll probably want ruby-xpath to go with it too.

The examples make it look as easy as this -

  require 'xml/xslt'

  xslt = XML::XSLT.new()
  xslt.xmlfile = "fuzface.xml"
  xslt.xslfile = "fuzface.xsl"

  out = xslt.serve()
  print out;

(This is also the libxslt-ruby package in Debian.)

I have to admit, though, that I tend to avoid XSL transformations
except in the direst of circumstances, instead using Ruby itself as my
transformation language (via the DOM, SAX, or REXML interfaces).

Just my two cents. good luck,
wad

If your generation logic is at all sophisticated, XSLT is going to be a profoundly cumbersome way to express that logic. It is reasonably simple with boolean switches and simple loops, but anything more complex then that and you find yourself typing in 50 lines of XSLT to do what could be done in 5 lines in Ruby.

My personal website publishing experiment uses XSLT for very simple transformations, and then Ruby for anything at all complicated. Then you just have to find a way to stitch those two together.

Francis

···

On Oct 19, 2004, at 10:52 AM, trans. (T. Onoma) wrote:

Nice. Thanks you for such a great reply! Very informative.

Why do you avoid XSLT? Because it is slow? Or?

Thanks,
T.

On Tuesday 19 October 2004 10:44 am, Will Drewry wrote:
> On the commandline, you can use xsltproc or xalan. (I'm sure there are
> others too). Both of these are apt-gettable in Debian. Xalan is from
> the Apache Foundation. It's been pretty solid for a while now.
>
> I've also seen these ruby projects floating around :slight_smile:
>
> http://raa.ruby-lang.org/project/ruby-xslt/
> http://raa.ruby-lang.org/project/libxslt/
> http://raa.ruby-lang.org/project/xslt4r/
>
> Ruby-xslt looks to have had a new version was released just recently.
> You'll probably want ruby-xpath to go with it too.
>
> The examples make it look as easy as this -
>
> require 'xml/xslt'
>
> xslt = XML::XSLT.new()
> xslt.xmlfile = "fuzface.xml"
> xslt.xslfile = "fuzface.xsl"
>
> out = xslt.serve()
> print out;
>
> (This is also the libxslt-ruby package in Debian.)
>
> I have to admit, though, that I tend to avoid XSL transformations
> except in the direst of circumstances, instead using Ruby itself as my
> transformation language (via the DOM, SAX, or REXML interfaces).
>
> Just my two cents. good luck,
> wad

you will run into tons of situations where xslt can't do what you
wanna do, because it's based on xml.. and when it's possible
you are either forced to duplicate code or using a even more
verbose way of expressing what you wanna do..

well, and sooner or later its verbosity will also annoy the hell out of you.

personally i would never recommend anybody to use xslt if you
are not absolutely forced to or doing something very simple.

ciao!
florian

···

On Oct 19, 2004, at 16:52 Uhr, trans. (T. Onoma) wrote:

Nice. Thanks you for such a great reply! Very informative.

Why do you avoid XSLT? Because it is slow? Or?

Well, the fact that XSLT is slow is one really annoying thing about
it. Another thing is that the syntax (XML!) is so cumbersome. As
others have pointed out the logic of a stylesheet for a nontrivial
transformation can be tricky, and the fact that XSLT syntax is so
messy makes an already difficult task harder than it should be.

···

On Tue, 19 Oct 2004 23:52:10 +0900, trans. (T. Onoma) <transami@runbox.com> wrote:

Why do you avoid XSLT? Because it is slow? Or?

That's too bad. So there is no _worthy_ standard declarative XML
transformation language then? So much for standards. I will use Ruby. Thanks.

T.

···

On Tuesday 19 October 2004 04:22 pm, Florian Weber wrote:

On Oct 19, 2004, at 16:52 Uhr, trans. (T. Onoma) wrote:
> Nice. Thanks you for such a great reply! Very informative.
>
> Why do you avoid XSLT? Because it is slow? Or?

you will run into tons of situations where xslt can't do what you
wanna do, because it's based on xml.. and when it's possible
you are either forced to duplicate code or using a even more
verbose way of expressing what you wanna do..

well, and sooner or later its verbosity will also annoy the hell out of
you.

personally i would never recommend anybody to use xslt if you
are not absolutely forced to or doing something very simple.

Standards are great for some things, awful for others. Data interchange and compatibility is a place where standards make our lives much easier. Turing-completeness is a place where standards are much less helpful. (Of course, the line between the two isn't always clear ...)

F.

···

On Oct 19, 2004, at 4:39 PM, trans. (T. Onoma) wrote:

On Tuesday 19 October 2004 04:22 pm, Florian Weber wrote:
> On Oct 19, 2004, at 16:52 Uhr, trans. (T. Onoma) wrote:
> > Nice. Thanks you for such a great reply! Very informative.
> >
> > Why do you avoid XSLT? Because it is slow? Or?
>
> you will run into tons of situations where xslt can't do what you
> wanna do, because it's based on xml.. and when it's possible
> you are either forced to duplicate code or using a even more
> verbose way of expressing what you wanna do..
>
> well, and sooner or later its verbosity will also annoy the hell out of
> you.
>
> personally i would never recommend anybody to use xslt if you
> are not absolutely forced to or doing something very simple.

That's too bad. So there is no _worthy_ standard declarative XML
transformation language then? So much for standards. I will use Ruby. Thanks.

trans. (T. Onoma) wrote:

> > Nice. Thanks you for such a great reply! Very informative.
> >
> > Why do you avoid XSLT? Because it is slow? Or?
>
> you will run into tons of situations where xslt can't do what you
> wanna do, because it's based on xml.. and when it's possible
> you are either forced to duplicate code or using a even more
> verbose way of expressing what you wanna do..
>
> well, and sooner or later its verbosity will also annoy the hell out of
> you.
>
> personally i would never recommend anybody to use xslt if you
> are not absolutely forced to or doing something very simple.

That's too bad. So there is no _worthy_ standard declarative XML transformation language then? So much for standards. I will use Ruby. Thanks.

I find XSLT quite worthy in its own way. It is a functional language, so you have to think in a different way to do looping and such. But for most simple things it seems to be too much work, though. If, for example, I want to take all foo elements and convert them to bar elements, REXML shines. As might Regexp.

If I want to do conditional transformations based on element names and attributes, REXML is simple. XSLT may be better for defining complex templates and patterns, as I have a hard time setting up state tracking past a certain level. But maybe that's just me.

An advantage to XSLT is that it is (presumably) portable. But I suspect that once people have settled on a platform and programming language, they are unlikely to switch down the line. (As an aside, how many people have worked on projects where Java was selected because it was "cross-platform", yet there was never any foreseeable need to jump platforms, and indeed the development company had complete say over the development and production platforms?)

I would like to see an XML transformation lib in Ruby that helped solve most general cases, so that people would not have to rewrite essentially the same code. REXSLT or something. But so far, in my work converting between OOo XML and HTML, the Ruby code seems simple enough. But I've not covered all transformation cases, and there have been times I thought XSLT might have been easier.

James

···

On Tuesday 19 October 2004 04:22 pm, Florian Weber wrote:
> On Oct 19, 2004, at 16:52 Uhr, trans. (T. Onoma) wrote:

T.

I think of XSLT as another templating language, like Erb or ColdFusion or what-have-you. Seems that the main benefit of a templating language is that, if you've got lots of static markup with a teensy bit of dynamic content, the template lets you see the static stuff clearly. For example,

<tr>
   <td>Name</td>
   <td><%= user.name %></td>
</tr>

is probably a lot easier to read than

tr_elt = doc.add_element( 'tr' )
td_elt1 = tr_elt.add_element( 'td' )
td_elt1.text = 'Name'
td_elt2 = tr_elt.add_element( 'td' )
td_elt2.text = user.name

Of course, templating code doesn't scale, because the static markup becomes the dominant mode of organizing the intent, and not the dynamic code. If you want to extract a method out of your Ruby code you can find a good place for it, but if I'm extracting a method out of Erb then it just makes me feel sorta dirty.

( And yes, I know that you're supposed to take that sort of stuff and put it in Ruby-only classes, which I often do. But I just as often have super-dynamic web pages to generate, and I'm not crazy about pulling certain chunks of HTML out of templating code and plopping them into straight Ruby. )

Anyway, I suppose I'm rambling a little. I just think there are some very profound, fundamental reasons why most templating systems still blow, and yet using straight Ruby to generate markup also sort of blows, and maybe others would have good ideas as to why that is. Could it be because of the broad organizational issues? Dunno.

Francis

···

On Oct 20, 2004, at 2:27 AM, James Britt wrote:

I find XSLT quite worthy in its own way. It is a functional language, so you have to think in a different way to do looping and such. But for most simple things it seems to be too much work, though. If, for example, I want to take all foo elements and convert them to bar elements, REXML shines. As might Regexp.

If I want to do conditional transformations based on element names and attributes, REXML is simple. XSLT may be better for defining complex templates and patterns, as I have a hard time setting up state tracking past a certain level. But maybe that's just me.

An advantage to XSLT is that it is (presumably) portable. But I suspect that once people have settled on a platform and programming language, they are unlikely to switch down the line. (As an aside, how many people have worked on projects where Java was selected because it was "cross-platform", yet there was never any foreseeable need to jump platforms, and indeed the development company had complete say over the development and production platforms?)

I would like to see an XML transformation lib in Ruby that helped solve most general cases, so that people would not have to rewrite essentially the same code. REXSLT or something. But so far, in my work converting between OOo XML and HTML, the Ruby code seems simple enough. But I've not covered all transformation cases, and there have been times I thought XSLT might have been easier.

Hi!

Don't know really if it is so helpful in this case, but
http://www.martinfowler.com/bliki/MovingAwayFromXslt.html has a nice article about this topic.

Henrik

Francis Hwang wrote:

I think of XSLT as another templating language, like Erb or ColdFusion or what-have-you. Seems that the main benefit of a templating language is that, if you've got lots of static markup with a teensy bit of dynamic content, the template lets you see the static stuff clearly. For example,

Interesting. I see XSLT as a transformational language, not a templating language, though it can be used for the latter. But if what you need is basic templating, then XSLT is overkill.

<tr>
  <td>Name</td>
  <td><%= user.name %></td>
</tr>

is probably a lot easier to read than

tr_elt = doc.add_element( 'tr' )
td_elt1 = tr_elt.add_element( 'td' )
td_elt1.text = 'Name'
td_elt2 = tr_elt.add_element( 'td' )
td_elt2.text = user.name

True. And likely easier to read than the corresponding XSLT. More often than not, I use REXML's stream or pull parser, catch events and whatnot, and just populate a template or interim data struture.

James