xsl 模板匹配忽略命名空间 [英] xsl template match ignore namespace

查看:33
本文介绍了xsl 模板匹配忽略命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过很多关于忽略命名空间的例子,但似乎无法在模板匹配中实现这个概念.

I've read a lot of examples about ignore namespaces but can't seem to bring this concept to fruition inside template match.

这是我的示例 xml:

Here's my sample xml:

<?xml version="1.0"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <Response xmlns:ResB="http://www.aaa.com/v1" xmlns:dpconf="http://www.datapower.com/param/config" xmlns:exsl="http://xmlns.opentechnology.org/xslt-extensions/common" xmlns="http://www.aaa.com/v2">
         <Status>
            <Code>00000</Code>
        </Status>
      </Response>
    </soapenv:Body>
</soapenv:Envelope>

而且我不能在输出中使用命名空间.以下是所需输出的示例:

And I can't have the namespace in the ouptut. Here's an example of the desired output:

<A>
   <Transformed>0000</Transformed>
</A>

这不是输出我的节点,那么我怎样才能有一个 xslt 来匹配响应节点并解决它?

This isn't outputting my nodes, so how can I have an xslt to match the Response node and work off of that?

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//*[local-name() = 'Response']">
<A>
<Transformed><xsl:value-of select="Status/Code"/></Transformed>
</A>

推荐答案

为什么要忽略命名空间?只需声明并使用它.

Why would you want to ignore the namespace? Just declare it and use it.

<xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:v2="http://www.aaa.com/v2"
  exclude-result-prefixes="v2"
>
  <xsl:template match="v2:Response">
    <A>
      <Transformed>
        <xsl:value-of select="v2:Status/v2:Code" />
      </Transformed>
    </A>
  </xsl:template>
</xsl:stylesheet>

这篇关于xsl 模板匹配忽略命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆