小编Yal*_*mar的帖子

xslt 将 utf-8 字符转换为不同的编码

这个问题是间歇性出现的,就是我执行了很多xslt转换都没有这个问题,然后在我最近的xslt转换中突然出现了。

我有大量的 html 输入文件,其结构类似于以下 a.html:

<html>
  <body>
    <div class="wrd">
      <div class="wrd-id">5</div>
      <div class="wrd-wrd">address</div>
      <div class="wrd-ipa">??dres,?a?dres</div>
    </div>
    <div class="a">...</div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我检查输入文件的编码时,我得到以下结果:

file -I a.html 
a.html: text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

我使用类似于以下 a.xslt 的 xslt 转换 html 文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
 <xsl:output omit-xml-declaration="yes" indent="yes" encoding="UTF-8" />
 <xsl:strip-space elements="*" />

 <xsl:template match="@*|node()" >
  <xsl:copy>
   <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
 </xsl:template>

 <xsl:template match="div[@class='a']" >
  <xsl:apply-templates select="*|node()" />
 </xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

我使用类似于以下 a.sh 的脚本:

#!/bin/bash
xsltproc --html a.xslt a.html > b.html
Run Code Online (Sandbox Code Playgroud)

更完整的 bash 脚本如下:

#!/bin/bash …
Run Code Online (Sandbox Code Playgroud)

xslt

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

xslt ×1