Xml xslt单独替换名称空间uri
在我的xml中,名称空间应替换为。我必须使用xslt1.0,单独替换uri部分非常具有挑战性。所有其他输出都应保持原样。如果不存在此名称空间,则应按原样将输入xml传递给输出 我的输入xmlXml xslt单独替换名称空间uri,xml,namespaces,xslt-1.0,Xml,Namespaces,Xslt 1.0,在我的xml中,名称空间应替换为。我必须使用xslt1.0,单独替换uri部分非常具有挑战性。所有其他输出都应保持原样。如果不存在此名称空间,则应按原样将输入xml传递给输出 我的输入xml <a xmlns:hj="http://abc.com/source/error"> <hj:b>sam</hj:b> </a> 山姆 预期产量 <a xmlns:hj="http://abc.com/source/error/i1"> &l
<a xmlns:hj="http://abc.com/source/error">
<hj:b>sam</hj:b>
</a>
山姆
预期产量
<a xmlns:hj="http://abc.com/source/error/i1">
<hj:b>sam</hj:b>
</a>
山姆
此XSLT将完成此工作。但是请注意,只有当输入XML的名称空间前缀等于hj:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:hjold="http://abc.com/source/error" xmlns:hj="http://abc.com/source/error/i1" exclude-result-prefixes="hjold">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="a[namespace-uri-for-prefix('hj', /*) != '']">
<a xmlns:hj="http://abc.com/source/error/i1">
<xsl:apply-templates select="@*|node()" />
</a>
</xsl:template>
<xsl:template match="hjold:*" >
<xsl:element name="hj:{local-name()}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
<xsl:template match="*" >
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
要在XSLT 1.0中使用,并且输出中的名称空间不重要,即使没有声明名称空间,请更改:
<xsl:template match="a[namespace-uri-for-prefix('hj', /*) != '']">
到
谢谢。对于xslt,名称空间前缀应该无关紧要。即使是xml,“>sam应该可以工作..而且xslt版本是1.0对不起,但是如果您想在xslt 1.0中使用它,并且名称空间不管它是否是结果,请将
更改为
标记,输入xml可以是任何内容。也就是说,元素可以是任何数字。只应替换名称空间。
<xsl:template match="a">