Search

Is it normal for outputted html to contain the xmlns attribute automatically? I’m not applying it anywhere in my xslt, yet is seems to be present in most of my elements?? (but not in elements like li)

No, it’s not normal. What’s your XSLT look like?

@designermonkey, would you mind posting your xslt?

Example, tpl.master.xsl (utilities folder)

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

<xsl:import href="../utilities/tpl.navigation.xsl" />
<xsl:import href="../utilities/tpl.javascript.xsl" />

<!-- Fallback $page parameter for navigation and title -->
<xsl:variable name="page"/>

<xsl:output method="xml"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    omit-xml-declaration="yes"
    encoding="utf-8"
    indent="yes" />

<xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
        <head>
            <meta content="IE=8" http-equiv="X-UA-Compatible"/>
            <meta http-equiv="content-type" content="text/html; charset=utf-8" />
            <xsl:call-template name="title" />
            <xsl:call-template name="css" />
            <xsl:call-template name="javascript" />
        </head>
        <body>
            <div id="con">
                <div id="header">
                    <xsl:apply-templates select="data/navigation" />
                </div>
                <div id="content">
                    <xsl:apply-templates />
                </div>
                <div id="footer">
                    <xsl:comment>Footer template here.</xsl:comment>
                </div>
            </div>
        </body>
    </html>
</xsl:template>

<xsl:template name="css">
    <xsl:param name="css-path" select="concat($workspace, '/assets/css/')" />
    <link rel="stylesheet" type="text/css" href="{$css-path}stylesheets.css" media="all" />
</xsl:template>

<xsl:template name="title">
    <xsl:choose>
        <xsl:when test="not($page = '')">
            <title><xsl:value-of select="data/pages/entry/headline"/> | <xsl:value-of select="$website-name"/></title>
        </xsl:when>
        <xsl:when test="$page-title = 'Home'">
            <title><xsl:value-of select="$website-name"/></title>
        </xsl:when>
        <xsl:otherwise>
            <title><xsl:value-of select="$page-title"/> | <xsl:value-of select="$website-name"/></title>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

which imports tpl.navigation.xsl (utilities folder)

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

<xsl:template match="navigation">
    <ul id="nav">
        <xsl:apply-templates select="page" />
        <xsl:apply-templates select="../navigation-pages/entry" />
        <li><a href="?debug">Debug</a></li>
    </ul>
</xsl:template>

<xsl:template match="navigation/page">
    <xsl:if test="types/type != 'javascript' or types/type != 'hidden'">
        <li>
            <a>
                <xsl:choose>
                    <xsl:when test="types/type = 'index'">
                        <xsl:attribute name="href"><xsl:value-of select="concat($root, '/')"/></xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="href"><xsl:value-of select="concat($root, '/', @handle, '/')"/></xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="@handle = $current-page and not($page)">
                    <xsl:attribute name="class">current</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="name"/>
            </a>
        </li>
    </xsl:if>
</xsl:template>

<xsl:template match="navigation-pages/entry">
    <li>
        <a>
            <xsl:attribute name="href"><xsl:value-of select="concat($root, '/', menu-label/@handle, '/')"/></xsl:attribute>
            <xsl:if test="menu-label/@handle = $page">
                <xsl:attribute name="class">current</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="."/>
        </a>
    </li>
</xsl:template>

</xsl:stylesheet>

Ok, so the <ul> is output like <ul xmlns="">, yet the <li>s aren’t… Also the <divs> in my output are too. Weird.

@ashooner, thanks for the link, but that makes no sense to me. I don’t understand namespaces at all…

Thanks anyway though, I think it might be the same problem?

Try changing your opening HTML tag by removing its attributes:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

To:

<html>

Nick is on the case lol ;)

Yeah, did that and it fixed it, also the xmlns attribute has been automagically added in to the output for <html> anyway! So, I’ve left the xml:lang attribute there and it’s all working perfectly now.

I didn’t realise that it would be getting added anyway. Super!

Like in my case, if you are using a xmlns like xmlns:g="http://code.google.com/intl/uk/apis/+1button/" inside your <xsl:stylesheet version="1.0"> the xmlns will be outputted in the first element (the html tag).

If you don't want this xmlns in your html5 files you will have to create the html element using <xsl:element name="html">.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details