English | Français | Deutsch | Magyar | >> 中文 << | Polski ZVON > Tutorials > XSLT Tutorial
>> 页 61 << | 上一条 | 下一条 | 目录 | 元素索引

encoding 属性指定了适用的编码方式。HTML 输出时应该在 HEAD 元素的开始标签后紧接着加上 META 元素,来指定字符的编码方式。 XSLT stylesheet 1 用 UTF-8 编码方式输出, XSLT stylesheet 2 使用 UTF-16, XSLT stylesheet 3 用 Cp1250。 在 XSLT stylesheet 4 中,请看你浏览器中间最下面窗口的源代码。xml 里面包含了指定字符集之外的字符,因此进行了转义符替换。

XSLT stylesheet 1

XML源码
<source>

<html>
     <head>
          <title>HTML</title>
     </head>
     <body>
          <h1> HTML output </h1> ?í?ala ?nek ko?ka pa?ez be?ka mě?ec vyr
     </body>
</html>

</source>

输出
<html>
  
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  
     
     <title>HTML</title>
     
  </head>
  
  <body>
     
     <h1> HTML output </h1>
     ?&iacute;?ala ?nek
     ko?ka pa?ez
     be?ka m&#283;?ec vyr  
     
  </body>
  
</html>

用HTML察看
HTML

HTML output

?í?ala ?nek ko?ka pa?ez be?ka mě?ec vyr
XSLT stylesheet
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
     <xsl:copy-of select="/source/*"/>
</xsl:template>


</xsl:stylesheet>



XSLT stylesheet 2

XML源码
<source>

<html>
     <head>
          <title>HTML</title>
     </head>
     <body>
          <h1> HTML output </h1> ?í?ala ?nek ko?ka pa?ez be?ka mě?ec vyr
     </body>
</html>

</source>

输出
þÿ<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-16">


<title>HTML</title>

</head>

<body>

<h1> HTML output </h1>
?&iacute;?ala ?nek
ko?ka pa?ez
be?ka m&#283;?ec vyr

</body>

</html>

用HTML察看
þÿ<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-16"> <title>HTML</title> </head> <body> <h1> HTML output </h1> ?&iacute;?ala ?nek ko?ka pa?ez be?ka m&#283;?ec vyr </body> </html>
XSLT stylesheet
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="html" encoding="UTF-16"/>
<xsl:template match="/">
     <xsl:copy-of select="/source/*"/>
</xsl:template>


</xsl:stylesheet>



XSLT stylesheet 3

XML源码
<source>

<html>
     <head>
          <title>HTML</title>
     </head>
     <body>
          <h1> HTML output </h1> ?í?ala ?nek ko?ka pa?ez be?ka mě?ec vyr
     </body>
</html>

</source>

输出
<html>
  
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=Cp1250">
  
     
     <title>HTML</title>
     
  </head>
  
  <body>
     
     <h1> HTML output </h1>
     ?&iacute;?ala ?nek
     ko?ka pa?ez
     be?ka m&#283;?ec vyr  
     
  </body>
  
</html>

用HTML察看
HTML

HTML output

?í?ala ?nek ko?ka pa?ez be?ka mě?ec vyr
XSLT stylesheet
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="html" encoding="Cp1250"/>
<xsl:template match="/">
     <xsl:copy-of select="/source/*"/>
</xsl:template>


</xsl:stylesheet>



XSLT stylesheet 4

XML源码
<source>

<html>
     <head>
          <title>HTML</title>
     </head>
     <body>
          <h1> HTML output </h1> ?í?ala ?nek ko?ka pa?ez be?ka mě?ec vyr
     </body>
</html>

</source>

输出
<html>
  
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  
     
     <title>HTML</title>
     
  </head>
  
  <body>
     
     <h1> HTML output </h1>
     ?&iacute;?ala ?nek
     ko?ka pa?ez
     be?ka m&#283;?ec vyr  
     
  </body>
  
</html>

用HTML察看
HTML

HTML output

?í?ala ?nek ko?ka pa?ez be?ka mě?ec vyr
XSLT stylesheet
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="html" encoding="ISO-8859-1"/>
<xsl:template match="/">
     <xsl:copy-of select="/source/*"/>
</xsl:template>


</xsl:stylesheet>