include homepage.en.yhtml2 page "YSLT – XSLT C style" { h1 id=intro > YSLT – an introduction p >> Especially the ¬ XSLT¬ programmer can benefit from YML. Usually many attributes of XSLT are annoying in programming praxis: >> ul { li >> the missing separation of ¬ indention¬ of the XSLT program and indention of the output text >> li > the complicated syntax li > the lack of good text escaping mechanisms (< and > are not seldom) li > ... } p > In short, it's ugly ;-) p >> Usually the result is, that many programmers are avoiding XSLT as a programming language. It's a pity, because for processing XML data, it can do much more than “formatting” as “stylesheets”. >> p >> The idea of YSLT now is to supply a simple language, which programmers want to use, to make the features of XSLT accessible to a broader base of people. >> p >> YSLT can be used much simpler; it's just a ¬ Y Language¬ for XSLT. I'm using it for my blog, here you can ¬ download YBlog2¬, a simple blogging software in YSLT. >> p > Here you can find the ¬yslt.yml2 YSLT specification¬. h2 id=hello > Hello, World p > In YSLT, the hello world program reads like this: Code || include yslt.yml2 textstylesheet template "/" | hello, world || p >> The `a href="" code > include` line includes the YSLT Y Language declarations. The second line generates an XSLT hello world program. You can generate it using: >> Code | % yml2c -o hello.xsl hello.ysl2 p > This results in the following program: Code || hello, world || p >> You can execute this program with any ¬ XSL processor¬, for example the Free Software ¬ xsltproc¬. >> Code || % yml2c -o hello.xsl hello.ysl2 % echo '' > empty.xml % xsltproc hello.xsl empty.xml hello, world % _ || p >> Or you can just use ¬toolchain#processor yml2proc¬: >> Code || % yml2proc -My hello.ysl2 hello, world % _ || h2 id=programming > Programming in YSLT p >> Because YSLT is just a ¬index#ylanguages Y Language¬ for XSLT, you can do anything with YSLT you can do with XSLT in just nicer syntax ;-) To read what XSLT is all about, I recommend ¬ the official W3C documentation for XSLT¬. >> p >> So this document is just an beginners guide, if you want to understand XSLT completely, better read the ¬ W3C¬ stuff. >> h3 > Programming YSLT means programming with a pure functional language. p >> Lovers of ¬ Lisp¬ or ¬ Haskell¬ will not see any problems. But many programmers are used to have a programming language with a ¬ procedural imperative paradigma¬ like ¬ Java¬, ¬ C¬/¬ C++¬ or ¬ Python¬. Why should they use a ¬ functional¬ language? >> p >> Actually, if a functional language is practical or not, depends of what's to do – “the right tool for the task”, one could say. >> p >> Because processing XML data means traversing a (document) tree, ¬ recursive¬ algorithms are a clear advantage. And this is the reason, why choosing a functional language is a good choice for that job. >> p >> It's a little bit like with ¬ SQL¬ – for it's job, it's excellent, but no-one wants to write a complete application in SQL (and also not in one of the Turing-complete SQL extension languages like ¬ PL/SQL¬). >> h3 id=htmlgen > Generating HTML out of a DSL p >> Of course, you can use YSLT as you would use XSLT. Let's say, you have data in XML documents, and you want to have an excerpt out of this data. This is a common task, comparable to «SELECT» data out of an SQL database. But we have no database, we have something like this file customers.yml2: >> Code || decl customer(*id, *name) { id *id, name *name }; list { customer 23, "Kurt Meier"; customer 42, "Lieschen Schmidt"; } || p >> Let's say, we want to output this into an ¬ XHTML¬ document, where the list is showed as a table. Then we would do the following: >> p > The XHTML document should be like the following and include the list in the body: Code || include yslt.yml2 stylesheet { template "/" html { head title "Customer List"; body apply "list"; } || p >> In the example above, stylesheet declares the main program. Then we define a template, which is executed automatically starting reading the root «'/'» of the document tree of the XML document we're processing. >> p > Using the XML document as input, we're creating this HTML tree: Code || Customer List