Skip to content

xml stylesheets do not properly support html features #10166

@solonovamax

Description

@solonovamax

🐛 bug report

*.xslt files included via <?xml-stylesheet ...?> do not properly support all html features, such as:

  • dependencies
  • inline scripts/styles
  • posthtml minification
  • etc.

Also somewhat related, but .xsl and .xslt files cannot be processed directly by parcel. Right now they can only be referenced via <?xml-stylesheet ...?>.
It would be super nice if they could just be processed directly, eg. parcel build file.xslt.
My usecase for this is that my rss feeds are dynamically generated, and I just want to insert a reference to the stylesheet at the top of them.

Sample stylesheet:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <html>
            <head>
                <meta name="viewport" content="width=device-width, initial-scale=1"/>
                <meta name="referrer" content="unsafe-url"/>
                <title>
                    <xsl:value-of select="/atom:feed/atom:title"/>
                </title>
                <link rel="stylesheet" href="/src/assets/scss/water/core.scss"/>
            </head>
        </html>
    </xsl:template>
</xsl:stylesheet>

🤔 Expected Behavior

html is properly processed.

Expected output:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <html>
            <head>
                <meta name="viewport" content="width=device-width, initial-scale=1"/>
                <meta name="referrer" content="unsafe-url"/>
                <title>
                    <xsl:value-of select="/atom:feed/atom:title"/>
                </title>
                <link rel="stylesheet" href="file.[hash].css"/>
            </head>
        </html>
    </xsl:template>
</xsl:stylesheet>

😯 Current Behavior

html is not properly processed.

Actual output:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <html>
            <head>
                <meta name="viewport" content="width=device-width, initial-scale=1"/>
                <meta name="referrer" content="unsafe-url"/>
                <title>
                    <xsl:value-of select="/atom:feed/atom:title"/>
                </title>
                <link rel="stylesheet" href="/src/assets/scss/water/core.scss"/>
            </head>
        </html>
    </xsl:template>
</xsl:stylesheet>

💁 Possible Solution

A solution to this is probably somewhat complicated.

I tried hacking something together myself, however the main issue I ran into was that if I processed the file as if it were html, then all of the xsl-prefixed tags get removed.

🔦 Context

I'm trying to include a stylesheet in rss & atom feeds.
For example, see: https://www.rss.style/

Example feed: https://www.rss.style/example.xml?feedurl=https%3A%2F%2Fnews.ycombinator.com%2Frss

💻 Code Sample

I don't have a full code sample atm, as I'm working in a project with a lot of stuff and it's very late.
I'll provide a full code sample later (remind me if I forget)

🌍 Your Environment

Software Version(s)
Parcel 2.15.1
Node 22.15.0
npm/Yarn 4.8.1
Operating System Arch Linux 6.14.4-arch1-2 x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions