简体   繁体   English

在XSLT中使用XMLNS的输出XML节点

[英]Output XML nodes that use a XMLNS in XSLT

I was given this code from a client but I'm not sure how to do a <xsl:for-each> to loop over these because of the a: xmlns. 我从客户端获得了这段代码,但是由于a: xmlns,我不确定如何执行<xsl:for-each>来遍历这些代码。

Here is the code 这是代码

<nodes xmlns:a="http://www.test.com/api/">
    <a:node>
        <a:Number>T123123</a:Number>
        <a:Url>http://www.link2.com/</a:Url>
    </a:node>
    <a:node>
        <a:Number>345345</a:Number>
        <a:Url>http://www.link2.com/</a:Url>
    </a:node>
    <a:node>
        <a:Number>456456456</a:Number>
        <a:Url i:nil="true"/>
    </a:node>
</nodes>

I've tried a bunch including the following: 我尝试了一堆包括以下内容:

<xsl:for-each select="nodes/a:node">

or 要么

<xsl:for-each select="a:nodes/a:node">

Any help really appreciated. 任何帮助真的很感激。

Before you can use a prefix, you need to first declare the prefix pointing to the corresponding namespace URI : 在使用前缀之前,需要首先声明指向相应名称空间URI的前缀:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:a="http://www.test.com/api/">

Namespace prefix in the XSLT can be different from the one in the source XML as long as both mapped to the same URI. XSLT中的命名空间前缀可以与源XML中的命名空间前缀不同,只要它们都映射到相同的URI。

It isn't clear what the context element in your xsl:for-each and what the correct XPath expression for it since your attempted XPath doesn't correspond to the sample XML posted, so I can't comment on that part. 由于您尝试的XPath与发布的示例XML不对应,因此尚不清楚xsl:for-each的context元素是什么,以及该元素的正确XPath表达式是什么,因此我无法对此部分发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM