Re: [w3c/webcomponents] [templates] If HTML Template Instantiation proposal is adopted, consider a HTML-native syntax (#695)

These could be just ordinary elements that you can style and query and insert anywhere you like without creating syntax errors, provided of course that you can live with the semantics of ordinary elements.

```xml
<p class="price">
  <choose>
    <when test="price > 1000">Ouch!</when>
    <when test="price > 100">Good</when>
    <otherwise>Great</otherwise>
  </choose>
</p>
```

This unnamespaced XSLT would also not throw "syntax errors", but it would of course also not work. The magic only happens when you invoke the API:

```js
mytemplate.createInstance(mydata);
```

- and this is where the syntax errors can be thrown and catched in JavaScript. The elements are in other words only special to the template processor, or at least that could be the path of least resistance. Choosing a template syntax is like choosing between tabs and spaces only with an infinite amount of options and of course the option to create your own. It doesn't matter if tabs are true, because the choice is not rational. I have colleagues that prefer `React.createElement('div')` to `<div></div>`, so I can only say that it would appeal to my *personal* feelings if the standardized syntax was to become a mix of plain HTML and DOM0-style inline JavaScript:

```js
<if test="parseInt(user.age, 10) > 21">
  <p>Welcome <span text="user.name.split(' ')[0]"></span>!</p>
</if>
```

- because that is how it already appears to work out of the box.

```js
<button onclick="document.body.append(usertemplate.createInstance(user));">Enter</button>
```

- but I am of course also not in charge of global XSS prevention. There is an argument to be made for solving this entirely within (the realm of JavaScript)[https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X], but if the solution should ultimately be sought in the family of "entirely distinct languages that are easily recognizable as templating languages" one could perhaps take inspiration from XQuery+JSONiq[1] since it has both curly braces *and* smiley faces `:)`

[1] Chapter 5 in [this PDF](https://www.w3.org/2011/10/integration-workshop/p/Documentation-0.1-JSONiq-Article-en-US.pdf) shows an appropriate example.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/695#issuecomment-341881903

Received on Saturday, 4 November 2017 08:56:09 UTC