Hacker News new | past | comments | ask | show | jobs | submit login

So, HTML did have includes and they fell out of favor.

The actual term include is an XML feature and it’s that feature the article is hoping for. HTML had an alternate approach that came into existence before XML. That approach was frames. Frames did much more than XML includes and so HTML never gained that feature. Frames lost favor due to misuse, security, accessibility, and variety of other concerns.






Unlike Framesets I think XML includes were never really supported in many browsers (or even any major browsers)?

I still like to use them occasionally but it incurs a "compilation" step to evaluate them prior to handing the result of this compilation to the users/browsers.


As it happens, the major browsers still can do XML 'includes' to some extent, since by some miracle they haven't torn out their support for XSLT 1.0. E.g. this outputs "FizzBuzz" on Firefox:

  <!-- fizz.xml -->
  <?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet type="application/xslt+xml" href="style.xslt"?>
  <fizz>Fizz<buzz/></fizz>
  
  <!-- style.xslt -->
  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="buzz">
      <xsl:value-of select="document('buzz.xml')"/>
    </xsl:template>
  </xsl:stylesheet>
  
  <!-- buzz.xml -->
  <?xml version="1.0" encoding="UTF-8"?>
  <buzz>Buzz</buzz>
You can even use XSLT for HTML5 output, if you're careful. But YMMV with which XML processors will support stylesheets.

Yep, and this can be used to e.g. make a basically static site template and then do an include for `userdata.xml` to decorate your page with the logged in user's info (e.g. on HN, adding your username in the top right, highlighting your comments and showing the edit/delete buttons, etc.). You can for example include into a variable `<xsl:variable name="myinfo" select="document('userdata.xml')"/>` and then use it in xpath expressions like `$myinfo/user/@id`. Extremely simple, good for caching, lightweight, very high performance. Easy to fail gracefully to the logged out template. You basically get your data "API" for free since you're returning XML in your data model. I will never understand why it didn't take off.

XML includes are blocking because XSL support hasn't been updated for 25 years, but there's no reason why we couldn't have it async by now if resources were devoted to this instead of webusb etc.


> if resources were devoted to this

You'd better not jinx it: XSL support seems like just the sort of thing browser devs would want to tear out in the name of reducing attack surface. They already dislike the better-known SVG and never add any new features to it. I often worry that the status quo persists only because they haven't really thought about it in the last 20 years.


Fortunately, XSLT is used by far too many high-importance websites (e.g. official government legal sites) for removing it to be a real threat.

> I will never understand why it didn't take off.

I’ve used XSLT in anger - I used it to build Excel worksheets (in XML format) using libXSLT. I found it very verbose and hard to read. And Xpath is pretty torturous.

I wish I could have used Javascript. I wish Office objects were halfway as easy to compose as the DOM. I know a lot of people hate on Javascript and the DOM, but it’s way easier to work with than the alternatives.


XQuery is basically XSLT with saner syntax.

Nice, didn't think of that approach and It should work very well for the purposes of static headers and footers.



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: