Reputation: 877
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.
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.
Upvotes: 1
Views: 32
Reputation: 89285
Before you can use a prefix, you need to first declare the prefix pointing to the corresponding namespace 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.
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.
Upvotes: 1