在database.xml的帮助下,使用xslt将utf回复为unicode
我想使用xslt将所有utf替换为unicode,如下示例所示 这里很多utf实体都在我的xml中,我只想在包含所有utf和unicode值的数据库文件的帮助下使用xslt替换为unicode 请参考下面给出的示例 database.xml:-在database.xml的帮助下,使用xslt将utf回复为unicode,xslt,xslt-2.0,Xslt,Xslt 2.0,我想使用xslt将所有utf替换为unicode,如下示例所示 这里很多utf实体都在我的xml中,我只想在包含所有utf和unicode值的数据库文件的帮助下使用xslt替换为unicode 请参考下面给出的示例 database.xml:- <entities> <entity utf8="°" unicode="x00B0" iso="deg" latin1="176"/> <entity utf8="Ã" unicode="x00ED" iso="iac
<entities>
<entity utf8="°" unicode="x00B0" iso="deg" latin1="176"/>
<entity utf8="Ã" unicode="x00ED" iso="iacute" latin1="237"/>
<entity utf8="é" unicode="x00E9" iso="eacute" latin1="233"/>
<entity utf8="ó" unicode="x00F3" iso="oacute" latin1="243"/>
<entity utf8="â¢" unicode="x2062" iso="InvisibleTimes" latin1="Not Available"/>
</entities>
输入:-
<article>
<documentinfo>
<title lang="eng">First report on the contribution of small-sized species to the copepod community structure of the southern Patagonian shelf (Argentina, 47-55°S)</title>
<author>
<lastname>Julieta</lastname>
<firstname>Carolina</firstname>
<middlename>Antacli</middlename>
<fullname>Carolina Antacli Julieta</fullname>
<corresponding>yes</corresponding>
<email>James@gmail.com</email>
<affiliation>Consejo Nacional de Investigaciones CientÃficas y Técnicas (CONICET). Av. Rivadavia 1917, C1033AAJ, Buenos Aires, Argentina,</affiliation>
<affiliation>Instituto Nacional de Investigación y Desarrollo Pesquero (INIDEP). Paseo Victoria Ocampo 1, B7602HSA, Mar del Plata, Argentina</affiliation>
<affiliation>Instituto de Investigaciones Marinas y Costeras (IIMYC), CONICET-Universidad Nacional de Mar del Plata, Argentina</affiliation>
</author>
另外。如果要更改文件的编码,最好使用iconv之类的工具。例如
iconv -f UTF-8 -t UCS-2LE input_UTF8.xml > output_UCS.xml
关于国际化和编码的信息可能也很有用
也就是说,角色映射确实与您上传的input.xml一起工作
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:character-map name="specialsigns">
<xsl:output-character character="°" string="x00B0"/>
<xsl:output-character character="í" string="x00ED"/>
<xsl:output-character character="é" string="x00E9"/>
<xsl:output-character character="ó" string="x00F3"/>
</xsl:character-map>
<xsl:output indent="yes" method="xml" use-character-maps="specialsigns"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这只是从中修改的样式表
当应用到您的输入时,我得到:
<article>
<documentinfo>
<title lang="eng">First report on the contribution of small-sized species to the copepod community structure of the southern Patagonian shelf (Argentina, 47-55&#x00B0;S)</title>
<author>
<lastname>Julieta</lastname>
<firstname>Carolina</firstname>
<middlename>Antacli</middlename>
<fullname>Carolina Antacli Julieta</fullname>
<corresponding>yes</corresponding>
<email>James@gmail.com</email>
<affiliation>Consejo Nacional de Investigaciones Cient&#x00ED;ficas y T&#x00E9;cnicas (CONICET). Av. Rivadavia 1917, C1033AAJ, Buenos Aires, Argentina,</affiliation>
<affiliation>Instituto Nacional de Investigaci&#x00F3;n y Desarrollo Pesquero (INIDEP). Paseo Victoria Ocampo 1, B7602HSA, Mar del Plata, Argentina</affiliation>
<affiliation>Instituto de Investigaciones Marinas y Costeras (IIMYC), CONICET-Universidad Nacional de Mar del Plata, Argentina</affiliation>
</author>
</documentinfo>
</article>
关于小型物种对巴塔哥尼亚大陆架南部桡足类群落结构的贡献的首次报告(阿根廷,47-55&x00B0;S)
朱丽叶
卡罗莱纳州
安塔克利
卡罗莱纳州朱丽叶酒店
对
James@gmail.com
国家科学调查委员会#x00ED;菲卡斯y T&#x00E9;cnicas(CONICET)。Av。里瓦达维亚1917,C1033AAJ,阿根廷布宜诺斯艾利斯,
国家调查研究所#x00F3;纽约州德萨罗·佩斯奎罗(INIDEP)。阿根廷马德普拉塔B7602HSA维多利亚奥坎波1号酒店
阿根廷马德普拉塔国立科尼塞特大学滨海和科斯特拉斯研究所(IIMYC)
所有的功劳都归于迪米特里·诺瓦切夫。我试过了,但什么也没得到。在XSLT 2.0上工作之后,为什么不向我们展示您迄今为止提出的代码,而不是让我们从头开始,猜测您的错误所在?如果输出应该是UTF-8,为什么它有像ó代码>而不仅仅是像一样的字符
?对不起!现在我更新了Dimitre Novatchev的所有xmlsee。我已经使用您的输入对其进行了测试,但是我得到了&#x00B0代码>,等等。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vReps" select="document('entities.xml')/entities/*"/>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" name="replace">
<xsl:param name="pText" select="."/>
<xsl:choose>
<xsl:when test="not($vReps/@utf8[contains($pText, .)])">
<xsl:value-of select="$pText"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="multiReplace">
<xsl:with-param name="pText" select="$pText"/>
<xsl:with-param name="pReps"
select="$vReps[contains($pText, @utf8)]"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="multiReplace">
<xsl:param name="pText"/>
<xsl:param name="pReps"/>
<xsl:choose>
<xsl:when test="$pReps">
<xsl:variable name="escaped">
<xsl:value-of select="concat('&#', $pReps[1]/@unicode, ';')" disable-output-escaping="yes"/>
</xsl:variable>
<xsl:variable name="vRepResult">
<xsl:call-template name="singleReplace">
<xsl:with-param name="pText" select="$pText"/>
<xsl:with-param name="pOld" select="$pReps[1]/@utf8"/>
<xsl:with-param name="pNew" select="$escaped"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="multiReplace">
<xsl:with-param name="pText" select="$vRepResult"/>
<xsl:with-param name="pReps" select="$pReps[position() >1]"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$pText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="singleReplace">
<xsl:param name="pText"/>
<xsl:param name="pOld"/>
<xsl:param name="pNew"/>
<xsl:if test="$pText">
<xsl:choose>
<xsl:when test="not(contains($pText, $pOld))">
<xsl:value-of select="$pText"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($pText, $pOld)"/>
<xsl:value-of select="$pNew" disable-output-escaping="yes"/>
<xsl:call-template name="singleReplace">
<xsl:with-param name="pText" select="substring-after($pText, $pOld)"/>
<xsl:with-param name="pOld" select="$pOld"/>
<xsl:with-param name="pNew" select="$pNew"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<article>
<documentinfo>
<title lang="eng">First report on the contribution of small-sized species to the copepod community structure of the southern Patagonian shelf (Argentina, 47-55&#x00B0;S)</title>
<author>
<lastname>Julieta</lastname>
<firstname>Carolina</firstname>
<middlename>Antacli</middlename>
<fullname>Carolina Antacli Julieta</fullname>
<corresponding>yes</corresponding>
<email>James@gmail.com</email>
<affiliation>Consejo Nacional de Investigaciones Cient&#x00ED;ficas y T&#x00E9;cnicas (CONICET). Av. Rivadavia 1917, C1033AAJ, Buenos Aires, Argentina,</affiliation>
<affiliation>Instituto Nacional de Investigaci&#x00F3;n y Desarrollo Pesquero (INIDEP). Paseo Victoria Ocampo 1, B7602HSA, Mar del Plata, Argentina</affiliation>
<affiliation>Instituto de Investigaciones Marinas y Costeras (IIMYC), CONICET-Universidad Nacional de Mar del Plata, Argentina</affiliation>
</author>
</documentinfo>
</article>