Skip to content

extensible style sheet language transformations

I want to present a quick recap example here, but be aware that this does not work in the current directory because of this error :

Error

Unsafe attempt to load URL from frame with URL . 'file:' URLs are treated as unique security origins.

The test files are one test.xml file that i want to use to transform into html output using an xslt file.

xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml">

    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>

    <xsl:template match="/persons">
        <html>
        <head> <title>Testing XML Example</title> </head>
        <body>
            <h1>Persons</h1>
            <table border="1">
            <xsl:apply-templates select="person">
                <xsl:sort select="family-name" />
            </xsl:apply-templates>
            </table>
        </body>
        </html>
    </xsl:template>

    <xsl:template match="person">
        <tr><td>
        <xsl:value-of select="family-name"/><xsl:text>, </xsl:text><xsl:value-of select="name"/>
        </td></tr>
    </xsl:template>
</xsl:stylesheet>

The base files contains some simple xml and the line that translates it into a html table format.

result
<?xml-stylesheet href="example2.xsl" type="text/xsl" ?>

<persons>
    <person username="JS1">
        <name>John</name>
        <family-name>Smith</family-name>
    </person>
    <person username="MI1">
        <name>Morka</name>
        <family-name>Ismincius</family-name>
    </person>
</persons>

As mentioned running this from the commandline :

chromium
chromium text.xml 

Will fail because of CORS problems, it tries to get example2.xsl from and that is not allowed. But put both files under apache, and you will see it works.