Is it possible to put a xml:lang or lang attribute to the html root-element <html> using xslt 2.0?

The problem is, that the only allowed attributes for xsl:stylesheet are: id, exclude-result-prefixes, extension-element-prefixes, version and of course xmlns. Other attributes are being ignored by any xslt-processor.

There must be a way to extend the element <html> I hope?

Thanks a lot.

Code (xhtml in this case):

<xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
   xmlns:fn="http://www.w3.org/2005/xpath-functions"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:tst="http://www.ma-buwi-fh.de"
   xmlns="http://www.w3.org/1999/xhtml"
   xml:lang="de">

<xsl:output method="xhtml"
   encoding="UTF-8"
   indent="yes"
   doctype-public='-//W3C//DTD XHTML 1.1//EN'
   doctype-system='http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'
    />

The result looks like this:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:tst="http://www.ma-buwi-fh.de"
  xmlns="http://www.w3.org/1999/xhtml">
有帮助吗?

解决方案

You are mistaking the stylesheet element (the root element of an XSLT stylesheet) for html (the root element of an HTML document).

The attributes you cite are the ones allowed for the stylesheet element. See the relevant part of the specification here.

So, specify the lang attribute on the html element you output, not on the stylesheet element.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

  <xsl:template match="/">
    <html lang="EN">
      <!--HTML content-->
    </html>
  </xsl:template>
</xsl:stylesheet>

If you want anyone to diagnose your actual problem, you must needs show your XSLT code.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top