xml - 如何从输出 xml 中删除 namespace ?

标签 xml xslt xpath namespaces xml-namespaces

下面是我的xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ms="http://www.test.com/schemas/test" 
xmlns:ns="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms ns">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<XMLResponse>           
    <xsl:apply-templates select="ms:ProductRS/ms:Product"/>
</XMLResponse>
</xsl:template>
<-- some templates here -->
</xsl:stylesheet>

在输出中我得到如下所示

<?xml version="1.0" encoding="UTF-16"?>
<XMLResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Product>-----</Product>
</XMLResponse>

我需要从 xml 输出中删除 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

最佳答案

要排除一个命名空间,那么你应该这样表示:-

exclude-result-prefixes="ms ns xsi"

基本上你的样式表是这样的:-

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ms="http://www.test.com/schemas/test" 
xmlns:ns="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms ns xsi">

关于xml - 如何从输出 xml 中删除 namespace ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9352412/

相关文章:

xml - python 请求分块响应

xml - 未找到 wix 安装程序架构

java - 如何在 XSLT 中迭代列表(例如 ArrayList)

xslt - XslCompiledTransform 最快的内存缓存

ruby - 从 HTML 中抓取轨道数据?

c++ - 在 MFC C++ 中创建 XmlSerializer

javascript - 如何获取 svg 文档中嵌入图像的真实(未缩放)大小?!

python - 解析 XSL 上同名的子元素

php - 使用 ZF 的 DOMElement 中的 Html

c# - XML SelectSingleNode 其中兄弟 = 'something'