-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XSLT-style templating spec #428
Comments
With the disclaimer that I have never used XSLTs... A big pain point we have in Zellij is the repetition created in our layouts. We have A long standing TODO I have is to find some sort of mechanism to solve this but I've mostly been putting this off because I don't want to deal with the usual dependency problems. I think these sorts of capabilities (especially if they'll be built in to the existing SDKs) can take away a lot of this work from me. |
@imsnif so, as far as I can tell/imagine, KDL templating would be a lot like your And yeah, it would be easy enough to put them in separate files that you pass directly to kdl-rs, and it'll apply the templates to a particular document parse for you, transforming things as needed. And, I would hope, giving you informative errors. For example:
We could, of course, go further. We could have a whole module system of imports/exports where you can distribute "libraries" of templates and everything. You could also get a lot fancier with how you select arguments and values and interpolate them around. Here's a fun one:
how does that sound so far? |
A XSLT-like styling language would, by default, recursively process all nodes (which if empty, would yield nothing) . So the default behavior of an XSLT processor on: <foo>
text1
<bar>text 2</bar>
<baz/>
</foo> would be
See: https://www.w3.org/TR/1999/REC-xslt-19991116#built-in-rule The pattern in XSLT is to define templates for the elements you want to transform (via custom output) So if your code above would take a KML file, like the one in your example: group pos=above {
cmd foo
cmd bar
cmd baz
} and produce, by default foo
bar
baz and, assuming that |
@emceeaich In my examples, above, the definition for
so the final expansion would be:
the |
That makes sense, my example was me thinking in the default behavior of XSLT. The default behavior in XSLT is to recursively process the tree, applying the default template, unless the stylesheet contains templates that match some expression in the document, if it exists. |
yeah. I think in my mind, since KDL isn't a markup language that's intended to be a layer on top of plain text, it makes more sense for us to be more explicit about how the data is passed around and applied. And it'll give us nicer errors to boot, imo. |
I guess the catch with this is that you couldn't, for example, use this templating system to generate non-KDL templates. In a way, this is more a "function definition" system than a "templating" system. |
Yes, setting the scope of what you expect it to do is the right thing. I do hope you find some of the ideas in XSLT useful. |
Hey @zkat - thanks for the detailed run-down. This indeed looks really cool. I initially thought this might help with the "magic" part you were referring to in the comments (that's the big pain point in this area as I'm not enthusiastic about implementing dependency resolution and all that is involved there). Would be cool to also have these features though, but one thing at a time :) I still think this is a super useful addition to KDL. |
Yeah I think we could provide some helpers around “including” templates |
We already have the equivalent of JSON Schema/XSD in the KDL Schema spec, but we don't have something that would map to XSLT--that is, a templating language for using KDL to transform input KDL into other KDL documents--or even non-kdl documents?
I'm not really sure how big a task this would be. I've never used XSLT in anger but I imagine there's quite a bit to it.
The text was updated successfully, but these errors were encountered: