Looking for a (pseudo) XSLT preprocessor/templater to make it less verbose [closed]

只谈情不闲聊 提交于 2019-11-30 22:57:18

You should be better ask: how to DSL the XSLT?

You might be interested in some practical example such as YSLT based on YML concept.

NOTE It should be better not to convert/preprocess the code to get an XSLT transform at all; instead, just emulate the way a processor parses the input document and use your own DSL.


You can also write your own DSL. You should use some scripting language which really makes DSL concept easy, as, for example, ruby. In ruby, you can achieve something very nice and clean like:

match "/" do
 value-of :foo
end

which could work as:

<xsl:template match="/">
 <xsl:value-of select="foo"/>
</xsl:template>

Another thing that worth to be mentioned is templating languages like erb. This is I think the only feasible alternative to XSLT in general (even if alternative here is a big compromise and you get lost very soon with procedural manipulation of nodes).


Note

I love XSLT verbosity and, because of this verbosity, I think XSLT code is much more readable then any other language (once you understand how templates work).

I don't recommend to search something for converting some different markup to XSLT code. Your final XSLT code will loose of readbility and its code will not be optimal at all.

I've seen a few attempts to do this over the years but none that seems to have been used by anyone other than its originator. I think, frankly, the verbosity of XSLT is something you quickly get used to. XSLT 2.0 is of course far less verbose than 1.0.

At Balisage last week Evan Lenz presented yet another attempt, called Carrot: this time not just a compact syntax for XSLT but a language that attempts to provide the union of XSLT and XQuery. Looks interesting, but I don't think there's an implementation yet (and I'd be surprised if it catches on...)

Paul Sweatte

Processing-instructions can be used to implement macros, such as in this unrelated question on Docbook.

Template:
<?echo gal?>

Code:
<xsl:variable name="gal" select="'howdy'"/>

<xsl:template match="processing-instruction('echo')">
  <xsl:value-of select="//xsl:variable/@select[../@name=current()]"/>
</xsl:template>

There's also a similar question which covers simplified parameter passing.

XMLPreprocess or oXML may also be of interest as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!