Rexsel — A simpler way of writing XSLT

Here should go questions about transforming XML with XSLT and FOP.
hughFR
Posts: 4
Joined: Thu Jun 13, 2024 1:18 pm

Rexsel — A simpler way of writing XSLT

Post by hughFR »

Hi

I have been working with XSLT/XML (using oXygen) for sometime
now (>20 years) and have been minded to look at alternative
ways of generating XSLT scripts. As a result I have produced a
language REXSEL that provides a simpler means of writing
XSLT stylesheets.

The syntax follows the same underlying structure as XSLT, but is written
in a form that is akin to languages such as C or Swift. I have written a
compiler, and an "uncompiler" for translating from Rexsel to XSLT and
vice-versa.

There is a command line compiler that runs on MacOS and Linux. It is
writtenn in Swift as a pair of Swift Packages: CRexsel (the command line
tool) and RexselKernel (the actual compiler). The latter is also
used as the heart of a MacOS only editor (very simple) which compiles
Rexsel code "on the fly" giving real time error reports and a symbol
table, although the app is not quite ready for release in the wild.

The following is a simple example of Rexsel

Code: Select all

stylesheet {
        version "1.0"
     
        function helloWorld {   // Translates to <template name="helloWorld">...
            element "div" {
                attribute "class"  "simpleBox"
                text "Hello World!"
            }
        }
    }
More information, downloads and news can be found on the Rexsel Web
site: https://www.rexsel.org/. The Rexsel site and the Paloose web site
both use Rexsel to produce the XSLT code that is used extensively
throughout. I have found that I write scripts much faster (and more
error free) using Rexsel.

Feel free to download and play with it. Any comments will be useful
to hear, either here or at the Email (hsfr@rexsel.org).

=================================
Hugh Field-Richards
www.hopvine-music.com
www.paloose.org
www.rexsel.org
Martin Honnen
Posts: 102
Joined: Tue Aug 19, 2014 12:04 pm

Re: Rexsel — A simpler way of writing XSLT

Post by Martin Honnen »

Which XSLT versions does that new syntax support? The current version of XSLT is 3.0 with support for XPath 3.1 and there has been ongoing work for a year and a half developing XSLT and XPath 4.0 (together with XQuery 4.0).
Radu
Posts: 9431
Joined: Fri Jul 09, 2004 5:18 pm

Re: Rexsel — A simpler way of writing XSLT

Post by Radu »

Hi,

I'm also curious, most XSLT template have a match, attributes like priority, how does this translate in your language?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Syd
Posts: 4
Joined: Fri Dec 24, 2010 5:45 pm

Re: Rexsel — A simpler way of writing XSLT

Post by Syd »

And if the keyword for <template> is “function”, what, pray tell, is the keyword for <function>? (If it is “template” I am not sure if I will break out laughing or swearing! :- )
hughFR
Posts: 4
Joined: Thu Jun 13, 2024 1:18 pm

Re: Rexsel — A simpler way of writing XSLT

Post by hughFR »

In regards to V2 and V4 of XSL I think it will only require me to add the extra keywords into the tokenizer and parser of the compiler. The underlying structure will be similar. I chose Version 1 to start with since my web sites use an ISP that only (currently) supports that version. I knew that Rexsel would almost certainly support later versions. But pragmatism ruled and I could test the end result more easily. I am happy to add the extra.

As far XPath V4 is concerned there should be no problem because Rexsel merely takes an XPath expression and passes it through when the code is generated. A future enhancement of Rexsel might be to check the XPath for correctness but it is not a pressing issue at present.

To answer Radu's post, that is, I hope, fairly simple to answer with an example.

Code: Select all

stylesheet {
    version "1.0"

    match  using "//concertList"  scope "lists" priority "6" {
      element "div" {
         attribute  "id" "concertListAndIndex"
   
         element "div" {
            attribute "id" "concertList" 
            apply-templates scope "lists"
         }
     }
   }
}
which translates to

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!-- Produced using Rexsel compiler 1.0 Build 189 on 20/03/2024 12:29:46 -->
<!-- No Errors -->
<!-- 
Symbols in context "stylesheet" in line 1, found: 1 symbol
[M] //concertList::lists           in line 4
 -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="//concertList" mode="lists" priority="6">
        <xsl:element name="div">
            <xsl:attribute name="id">
                <xsl:text>concertListAndIndex</xsl:text>
            </xsl:attribute>
            
            <xsl:element name="div">
                <xsl:attribute name="id">
                    <xsl:text>concertList</xsl:text>
                </xsl:attribute>
                
                <xsl:apply-templates mode="lists"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
Sorry for the long post, but I hope that answers the question.

Regards, Hugh
hughFR
Posts: 4
Joined: Thu Jun 13, 2024 1:18 pm

Re: Rexsel — A simpler way of writing XSLT

Post by hughFR »

Hi Syd

Changing the "function" keyword would be very simple (a couple of lines of Swift). I would probably change it to "proc" or "procedure" (my Algol roots), or even possibly "func". Changing my existing Rexsel source files would also be trivial. I assume that this is a Version 4 keyword ?

I will issue a new version of the RexselKernel shortly to change "function" to one of the above. Any suggestions for alternatives would be gratefully received.

Thanks for the warning, much appreciated — hilarity and bad language duly avoided :-)
xephon
Posts: 159
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: Rexsel — A simpler way of writing XSLT

Post by xephon »

Hello Hugh,
Thank you so much, that you invest life time and love into this project. It is really outstanding, if someone dedicates so much energy into something that he or she believes should be done.

I totally agree with you that coding in XML (XSLT is also XML) is no fun, verbose, hard to read, and error prone. What I can tell you, that I asked a while ago the XSLT developers (so mainly Michael K.) for a no XML flavor of XSLT. I don't remember the link anymore, but IIRC the answer was something like "Good idea, would be nice to have, but no time and resources available."
What I'm trying to say, is, that a different attempt could be to create an XML-free XSLT syntax, which could be part of the XSLT standard. If you volunteer for that, you might find open ears.
stefan-jung.org – Your DITA/DITA-OT XML consultant
hughFR
Posts: 4
Joined: Thu Jun 13, 2024 1:18 pm

Re: Rexsel — A simpler way of writing XSLT

Post by hughFR »

Hi Stephan

Thanks for the encouraging post. While I certainly have invested a certain
amount of my time (I started Rexsel in February of this year after a light-bulb
moment when pretty-printing XSLT for a Web site and realising that I could turn
it into a two way process). Selfishly I wanted to do it fairly quickly as
I wanted it for other sites. Speed was also a factor as I am the wrong
side of 75 :-)

Rexsel was started as scratching a technical itch so I certainly felt it was
a good use of my time. I contacted James Clark at the W3C who also seemed to
think it was worth releasing.

I do have a formal syntax for Rexsel which I am refining as I develop Rexsel. It
is not 100% ready for the world, albeit close. I am happy to donate it to
become part of the XSLT standard, but having someone assist me in this would be
helpful.

Anyone can download the Packages and try them. And, who knows, someone may produce
a decent editor to replace the rather crude one that I have done based on the
RexselKernel.
Post Reply