简体   繁体   English

将属性放入 <html> xslt 2.0的根元素

[英]Puting attributes to the <html> root-element with xslt 2.0

Is it possible to put a xml:lang or lang attribute to the html root-element <html> using xslt 2.0? 是否有可能使用xslt 2.0将xml:langlang属性放入html根元素<html>

The problem is, that the only allowed attributes for xsl:stylesheet are: id , exclude-result-prefixes , extension-element-prefixes , version and of course xmlns . 问题是, xsl:stylesheet唯一允许的属性是: idexclude-result-prefixesextension-element-prefixesversion以及xmlns Other attributes are being ignored by any xslt-processor. 任何xslt处理器都会忽略其他属性。

There must be a way to extend the element <html> I hope? 我希望有一种扩展元素<html>吗?

Thanks a lot. 非常感谢。

Code (xhtml in this case): 代码(在这种情况下为xhtml):

<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). 您将htmlstylesheet元素(XSLT样式表的根元素)误认为是html (HTML文档的根元素)。

The attributes you cite are the ones allowed for the stylesheet element. 您引用的属性是stylesheet元素允许的属性。 See the relevant part of the specification here . 请参阅该规范的相关部分在这里

So, specify the lang attribute on the html element you output, not on the stylesheet element. 因此,请在输出的html元素(而不是stylesheet元素)上指定lang属性。

<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. 如果您想让任何人诊断您的实际问题,则必须显示您的XSLT代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM