Open charring opened 9 months ago
I had been trying Chrome. I decided to try Firefox These patterns worked in Firefox:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template ...
....
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
....
I decided to this in Chrome and it worked. It also works in Firefox.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
....
I'm reopening as this should be documented in the xslt-template example. And that doc should use a more realistic example with HTML generation.
https://htmx.org/extensions/client-side-templates/#full-xslt-html-example
I'm curious what the use case for client side templates is in the context of HTMX. I've never done anything with XSLT in a browser, so please forgive me my silly question. Why not simply render the HTML that eventually results from the XSLT on the server as HTML and give that to the client? That's what HTMX is all about in my eyes.
@svenberkvens I don't have a use-case - not yet anyway. I'm just learning HTMX and find the client-side templates to be convenient for that learning. I use xslt templates client-side in this learning to mock things that would - in a real app - come from the server. I've been learning and experimenting by using a generic echo http endpoint that I created. Here's an example of one such experiment:
https://codepen.io/charring/pen/dyaqPgx
The htmxecho service is stateless. It just echos back what was sent. I'm learning how to deal with state in the client-side elements and in the state interchange with the server.
In answer to your "Why not simply render on the server" question, my answer is that I'm doing experiments to create some common user interface patterns that perhaps do not need anything rendered by the server - because there's no state on the server that is required.
I've done extensive XSLT in the browser in the past when working with a backend that exposes a REST API. Browsers continue to support XSLT mainly because there are a lot of commercial applications that depend upon it. Google has threatened in the past to remove support, but they always get pushback from developers.
Thank you for your very thorough response! I get where you're coming from now.
I can't help you with any examples, but maybe your own work on codepen is suitable for the documentation of the client side templates extension in HTMX?
Yes, I find myself making examples in order to learn it. And I'll put up a page with my learnings and with links to the codepen examples.
I am using the XSLT client side when consuming a third party API that delivers XML. One example is the Subversion httpd module that returns folder listing results as a simple XML structure one level at a time. With htmx we can expand the directory tree level by level as most file explorers work.
The doc and the test both just generate a text result not an HTML result. Can someone point me at a working example of client-side-templates that uses xslt-template to generate an html fragment?