[英]Remove a string from the Element Name of XML using XSLT?
My XML looks like this. 我的XML看起来像这样。
<?xml version="1.0" encoding="utf-8"?>
<ns0:Respuesta xmlns:ns0="http://www.siebel.com/xml/SBL_EAI_RC13_SC03_HPFMS_ConsultaTajetadeCreditoenBlackList_29004_Respuesta">
<ns0:Error>
<ns0:Codigo>30</ns0:Codigo>
<ns0:Descripcion>Numero no encontrado en la lista</ns0:Descripcion>
<ns0:Sistema>adaptadorCFMS</ns0:Sistema>
<ns0:Tipo>Adaptador</ns0:Tipo>
<ns0:TimeStamp>2014-06-26T14:40:42</ns0:TimeStamp>
<ns0:IdHost>medusa10</ns0:IdHost>
</ns0:Error>
</ns0:Respuesta>
I need to remove the 'ns0:' part of elements. 我需要删除元素的“ ns0:”部分。 It doesnt necessarily need to be 'ns0:', it can be 'ns1:' or 'ns2: , hence all those that look like that starting with 'ns' needs to be removed. 它不必一定是'ns0:',它可以是'ns1:'或'ns2 :: ,因此需要删除所有看起来像以'ns'开头的内容。
The 'ns0:' is also present as a suffix in the namespace xmlns attribute which needs to be removed too. “ ns0:”也作为后缀出现在名称空间xmlns属性中,该后缀也需要删除。
so the output xml should look like this. 因此输出xml应该如下所示。
<?xml version="1.0" encoding="utf-8"?>
<Respuesta xmlns="http://www.siebel.com/xml/SBL_EAI_RC13_SC03_HPFMS_ConsultaTajetadeCreditoenBlackList_29004_Respuesta">
<Error>
<Codigo>30</Codigo>
<Descripcion>Numero no encontrado en la lista</Descripcion>
<Sistema>adaptadorCFMS</Sistema>
<Tipo>Adaptador</Tipo>
<TimeStamp>2014-06-26T14:40:42</TimeStamp>
<IdHost>medusa10</IdHost>
</Error>
</Respuesta>
Can you please help me with this? 你能帮我吗? I would really appreciate your help. 我将衷心感谢您的帮助。
Write a template that strips namespace prefixes from element nodes using eg 编写一个模板,使用例如从元素节点中删除名称空间前缀的模板
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
then add a template copying attributes, comments, text 然后添加一个模板,复制属性,注释,文本
<xsl:template match="@* | text() | processing-instruction() | comment()">
<xsl:copy/>
</xsl:template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.