【发布时间】:2015-06-05 20:23:18
【问题描述】:
我正在尝试转换 XML 文档并修改单个元素的属性,但如果根元素具有命名空间属性,则不会应用转换。只需删除 xmlns 就可以很好地使用我的代码。
我的 XML:
<?xml version="1.0"?>
<BIDomain xmlns="http://www.oracle.com/biee/bi-domain">
<BIInstance name="coreapplication">
<SecurityOptions sslManualConfig="false" sslEnabled="false" ssoProvider="Custom" ssoEnabled="false">
<SecurityService>
<EndpointURI>bisecurity/service</EndpointURI>
</SecurityService>
</SecurityOptions>
</BIInstance>
</BIDomain>
使用的 XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" standalone="yes" />
<!-- Copying everything -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- Add the new attributes -->
<xsl:template match="SecurityOptions">
<xsl:copy>
<xsl:attribute name="ssoProviderLogoffURL"/>
<xsl:attribute name="ssoProviderLogonURL"/>
<xsl:attribute name="sslVerifyPeers">
<xsl:value-of select="'false'" />
</xsl:attribute>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
最终结果是相同的 XML。如果我从根元素中删除命名空间定义
<BIDomain xmlns="http://www.oracle.com/biee/bi-domain"> 转换正常应用。我假设我做错了什么并且命名空间属性干扰了匹配。
有什么想法吗?
【问题讨论】: