xslt - 如何从 XML 标记中删除名称空间
问题描述
您能否告诉我如何xmlns="http://ws.apache.org/ns/synapse"
从 XML 标记中仅删除名称空间?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:rfc:functions">
<soapenv:Body>
<urn:BAPI_QM_DEFECT_RECORDING>
<AMOUNT xmlns="http://ws.apache.org/ns/synapse">1</AMOUNT>
<DEFECT_CODE xmlns="http://ws.apache.org/ns/synapse">393</DEFECT_CODE>
<DEFECT_DESC xmlns="http://ws.apache.org/ns/synapse">393</DEFECT_DESC>
<DEFECT_PID xmlns="http://ws.apache.org/ns/synapse">601000</DEFECT_PID>
<INSPID xmlns="http://ws.apache.org/ns/synapse"/>
<ORDER xmlns="http://ws.apache.org/ns/synapse">20262950</ORDER>
<ORIGIN_PID xmlns="http://ws.apache.org/ns/synapse">600000</ORIGIN_PID>
<OVER_CONSUMP xmlns="http://ws.apache.org/ns/synapse">text</OVER_CONSUMP>
</urn:BAPI_QM_DEFECT_RECORDING></soapenv:Body></soapenv:Envelope>
解决方案
您可以通过创建元素 use local-name 来使用下面的代码,该元素将采用没有命名空间的名称:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:sap-com:document:sap:rfc:functions">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="urn:BAPI_QM_DEFECT_RECORDING/*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
推荐阅读
- python - 如何标记文本语料库?
- angular - 角 | 使用 httpInterceptor 迟到的错误响应
- r - 使用查找表替换部分字符串
- python - 当元素的顺序发生变化时通过xpath提取元素(即使相对xpath也在变化)
- neo4j - Neo4j - 从嵌套的 JSON 文件和列表创建节点
- angular - 如果使用 [].concat() 组合多个数组,Angular @NgModule 导入不会看到模块
- numpy - numpy 点积的爱因斯坦符号
- c# - 使用 MS Graph 进行机器人身份验证 - 如何在不手动输入的情况下动态读取 6 位代码
- c# - c#aspx如何在页面上执行拆分
- python - Python3 线程还是 aiohttp?