13 ms·
For RSS feeds, XSLT stylesheets are used to display a human-readable version in the browser. Random example: https://lepture.com/en/feed.xml https://lepture.co
by sltkr 11mo ago
For RSS feeds, XSLT stylesheets are used to display a human-readable version in the browser.
Random example: https://lepture.com/en/feed.xml https://lepture.com/en/feed.xml
This is useful because feed URLs look the same as web page URLs, so users are inclined to click on them and open them in a web browser instead of an RSS reader. (Many users these days don't even know what an RSS reader is). The stylesheet allows them to view the feed in the browser, instead of just being shown the XML source code.
- nomercy400 11mo agoAren't there other ways to load and parse a technical format like RSS to a human-readable format? Like you would do with JSON. Or can't you polyfill this / use a library to parse this?
- sltkr 11mo agoYou can do the transformation server-side, but it's not trivial to set it up. It would involve detecting the web browser using the "Accept" header (hopefully RSS readers don't accept text/html), then using XSLT to transform the XML to XHTML that is sent to the client instead, and you probably need to cache that for performance reasons. And that's assuming the feed is just a static file, and not dynamically generated. In theory you could do the transformation client side, but then you'd still need the server to return a different document in the browser, even if it's just a stub for the client-side code, because XML files cannot execute Javascript on their own. Another option is to install a browser extension but of course the majority of users will never do that, which minimizes the incentive for feed authors to include a stylesheet in the first place.
- nomercy400 11mo agoHow about using Javascript to fetch the XML (like you would do with JSON), and then parse/transform it with a Javascript or wasm XSLT library? Just like you would do with JSON. You need a server to serve Json as well. Basically, see XML as data format. RSS readers are not chrome, so they have their own libraries for parsing/transforming with XSLT.
- _heimdall 11mo agoNot without servers rendering the HTML or depending on client-side JS for parsing and rendering the content. Its also worth noting that the latest XSLT spec actually supports JSON as well. Had browsers decided to implement that spec rather than remove support all together you'd be able to render JSON content to HTML entirely client-side without JS.
- miki123211 11mo agoYou can do the same by checking Accept headers, User-Agent if you truly must.
- bawolff 11mo agoWhy is this so critical? We dont due this for any other format. If you put an ms office document on a page, we dont have the browser render it, we download it and pass it off to a dedicated program. Why is RSS so special here?
- sltkr 11mo agoI don't think it's a critical feature, but it is nice-to-have. Imagine if you opened a direct link to a JPEG image and instead of the browser rendering it, you'd have to save it and open it in Photoshop locally. Wouldn't that be inconvenient? Many browsers do support opening web-adjacent documents directly because it's convenient for users. Maybe not Microsoft Word documents, but PDF files are commonly supported.
- bawolff 11mo agoYeah, but browsers actually make use of that format. And its not like you can add a special header to jpg files to do custom reformatting of the jpeg via a turing complete language. Browsers just display the file.
- ruszki 11mo agoIf you think about it, basically nothing except HTML is a critical function of browsers. You can solve everything just with that. We don’t even need CSS, or any custom styling at all. JavaScript is absolutely not necessary.
- yoz-y 11mo agoYes and no. You can have a document without CSS but you can’t style it. You can have a document without JavaScript but only a static one (still interactive, but only though forms) On the other hand, you can replace XSLT with server side rendering, or JavaScript. It does not serve a truly unique function.
- basscomm 11mo ago