Skip to content
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

Extend client-side-templates to handle XSLT transformations #1210

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

jyrimatti
Copy link
Contributor

This PR extends client-side-templates with XSLT support.
Uses browser built-in XSLTProcessor, so no external dependencies are needed.
Since this is only a fourth supported templating engine, I don't think it adds any complexity.

Please let me know if I can improve this in any way!

A couple of other things, which I didn't include:

I don't know how external script support for the other engines is supposed to work, but at least for XSLT it seemed to work using an object tag (see https://lahteenmaki.net/davtest/ for an example). However, I didn't include anything about it in the documentation since I guess the handling should somehow be unified across all supported engines, or what do you think?

I noticed that the HTML template tag is often not useful for templates (dah...) since the browser seems to enforce HTML validity inside the tag. But templates often contain invalid HTML, for example when looping over rows inside a table, which the browser doesn't seem to accept. Therefore I used the script tag in the example. Maybe this problem should be somehow mentioned in the extension documentation, or what do you think?

@jyrimatti
Copy link
Contributor Author

Ran into another use case, where this would be useful:
Some data in the Internet is available as RSS (like Mastodon toots or GoodReads lists), which you could then include in your web page like this, by just writing a suitable XSLT transformation (in this case file rss.xml):

<script src="https://unpkg.com/htmx.org@1.8.5"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/client-side-templates.js"></script>
<object id="tmpl" data="rss.xml"></object>
<div hx-get=”https://mastodon.online/@jyrimatti.rss” hx-trigger=”load” hx-ext=”client-side-templates” xslt-template=”tmpl”>loading…</div>
<object id=”tmpl” data=”rss.xml” style=”position:absolute; left:999999px”></object>

@1cg
Copy link
Contributor

1cg commented Feb 23, 2023

Very cool!

Would you mind pulling the documentation out into it's own little subsection (maybe we need headers for the mustache version and the xslt version) so it doesn't conflict w/ the existing dev branch?

@jyrimatti
Copy link
Contributor Author

Hi,

is this what you had in mind? Please feel free to modify as you wish, you are much better at writing documentation than I am :)

@alexpetros
Copy link
Collaborator

Hi @jyrimatti, I'm sorry this has been sitting for so long! Would you mind rebasing this against the current dev branch so that we can look at it for an upcoming release?

@jyrimatti
Copy link
Contributor Author

Hi,
don't worry about it! I'm already using this myself, so getting it merged would just help other people to discover the possibility.

Please let me know if there's something more I could help with :)

@alexpetros
Copy link
Collaborator

This looks super! I know that we have XSLT users and I'm sure they would take advantage of it.

@alexpetros alexpetros added the ready for review Issues that are ready to be considered for merging label Sep 19, 2023
@1cg 1cg merged commit 048f98c into bigskysoftware:dev Sep 19, 2023
1 check passed
@jyrimatti jyrimatti deleted the xslt-templates branch January 21, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Issues that are ready to be considered for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants