Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML is to HAML as XSLT is to ...?

I just discovered HAML, and love its succinctness and readability. Is there any kind of equivalent for XSLT? In particular, I would love something that makes it easier to distinguish between the angle-bracket-containing output and the angle-bracket-containing markup itself.

If there is not a specialised XSLT abstraction language, is there at least a generic form for XML which would also work?

EDIT For fun, I just did a quick test of using actual Haml (actually HamlPy) to generate XSLT. Shortcomings I observed:

  • hyphenated element names aren't supported (in HamlPy at least)
  • %xsl:foo is not succinct enough. A special character for the XLS namespace, like #foo would be better.
  • HTML-specific rules get in the way (in my case, the special self-closing tag rules for <meta> are a problem)
  • %xsl:attribute(name="foo" value="blah") is still way too verbose. something like .foo="blah" would be better.
  • certain attributes like select are very common, and could be made implicit: #value-of "./a[@href]"
  • features like - and = for processing logic aren't needed, so could be repurposed for something like xquery or xpath. Or maybe {foo} could be a shorthand for <xsl:value-of select="foo"/>. That'd be cool: %p(style={../[@style]})
like image 746
Steve Bennett Avatar asked Jan 09 '13 00:01

Steve Bennett


People also ask

What is XSLT used for?

XSLT is used to transform XML documents into XHTML documents, or into other XML documents.

Can I use XSL in HTML?

XSL can be used server-side and client-side. The XSL Submission has two classes of output: DSSSL-style flow objects and HTML tags.

How is XSLT used in web development?

XSLT is most often used to convert data between different XML schemas or to convert XML data into web pages or PDF documents.

How does an XSLT processor use an XSLT style sheet with an XML document?

XSLT Processor takes the XSLT stylesheet and applies the transformation rules on the target XML document and then it generates a formatted document in the form of XML, HTML, or text format. This formatted document is then utilized by XSLT formatter to generate the actual output which is to be displayed to the end-user.


2 Answers

There have been many attempts to define "user-friendly" or "compact" non-XML concrete syntax for XSLT. As far as I know, none of them have ever been used in anger by anyone other than the inventor. In the end, having a good editor that understands XSLT (e.g. oXygen) gives a much better productivity boost than having a more concise syntax.

like image 134
Michael Kay Avatar answered Sep 28 '22 05:09

Michael Kay


Thanks to pointers from Michael Kay:

RXSLT

"Real XSLT": http://www.wilmott.ca/rxslt/rxslt.html

template doc
   apply-templates
 template doc/title
   <H1>{apply-templates}</H1>
 template doc/para
   <P>{apply-templates}</P>

XSLTXT

Very old (2002), abandoned long ago. Example:

tpl .name "foo" ("a", "b")
  "SELECT "
  val "$a"
  " FROM "
  val "$b"

http://savannah.nongnu.org/projects/xsltxt

LX

A lisp-ish compact XML notation. Not sure if there is any special treatment for XSLT:

;; The XSLT identity transformation
(lx:namespace ((#f "http://www.w3.org/1999/XSL/Transform"))
  (stylesheet version: 1.0
    (template match: "node()|@*"
      (copy
        (apply-templates select: "@*|node()")))))

http://nxg.me.uk/dist/lx/

like image 22
Steve Bennett Avatar answered Sep 28 '22 06:09

Steve Bennett