Xml 如何用unicode字符替换嵌套在文本中的元素
在下面的示例中,我有一个嵌套的空元素,必须用空格字符替换:Xml 如何用unicode字符替换嵌套在文本中的元素,xml,xslt,xpath,Xml,Xslt,Xpath,在下面的示例中,我有一个嵌套的空元素,必须用空格字符替换: 这是输入xml文件: <?xml version="1.0" encoding="UTF-8"?> <catalog> <cd> <title>Empire<s/>Burlesque</title> <artist>Bob<s/>Dylan</artist> </cd> &
输出文档上的代码>
这是输入xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire<s/>Burlesque</title>
<artist>Bob<s/>Dylan</artist>
</cd>
<cd>
<title>Scareface</title>
<artist>Al<s/>Pacino</artist>
</cd>
</catalog>
帝国式
博迪兰
胆小鬼
阿尔·帕西诺
这是xsl文件:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="/">
<root>
<xsl:apply-templates select="/catalog"/>
</root>
</xsl:template>
<xsl:template match="catalog">
<xsl:for-each select="cd">
<title>
<xsl:value-of select="title"/>
</title>
<artist>
<xsl:value-of select="artist"/>
</artist>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我想要的是这样的输出:
<root>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<title>Scareface</title>
<artist>Al Pacino</artist>
</root>
皇帝讽刺剧
鲍勃·迪伦
胆小鬼
阿尔帕西诺
请注意帝国和滑稽剧之间的空格。当前,输出表示中间没有空格字符的名称。任何帮助都将不胜感激。如何:
XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/catalog">
<root>
<xsl:apply-templates select="cd/title | cd/artist"/>
</root>
</xsl:template>
<xsl:template match="title | artist">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="s">
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>