Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xsl:element标记进行html转换_Html_Xslt_Tags - Fatal编程技术网

使用xsl:element标记进行html转换

使用xsl:element标记进行html转换,html,xslt,tags,Html,Xslt,Tags,我正在将xsl文档转换为html,如下所示: <xsl:template match="/"> <html> <head> <title>Title</title> </head> <body> Blah-blah </body> </html> </xsl:template>

我正在将xsl文档转换为html,如下所示:

  <xsl:template match="/">
    <html>
      <head>
        <title>Title</title>
      </head>
      <body>
        Blah-blah
      </body>
    </html>
  </xsl:template>
哪种变体是正确的
致以最良好的祝愿。

文本结果元素(即您的第一种方法)更短、更易于键入和阅读。我建议仅在需要根据输入数据动态计算元素名和/或名称空间的情况下使用
xsl:element
,例如

<xsl:template match="*">
  <xsl:element name="{translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')}">
     <xsl:apply-templates/>
  </xsl:element>
</xsl:template>


在其他情况下,我会像在第一个示例中一样使用文本结果元素。但是在结果方面没有对错之分,两种变体都给出了相同的结果树。

哦,我没有考虑这种情况(元素名计算)。谢谢,我现在更清楚了!
<xsl:template match="*">
  <xsl:element name="{translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')}">
     <xsl:apply-templates/>
  </xsl:element>
</xsl:template>