Ludo
Ludo

Reputation: 343

issues when retrieving XML attributes with namespaces with XSLT

Basically, I've got an XML like this :

<com:myObject xmlns="myNamespaceUrl" xmlns:ref="myUrl/reference" xmlns:type="myUrl/type" xmlns:com="myUrl/common">
   <com:myNode help="12" ref:label="myLabel" type:cen="true">text</com:myNode
</com:myObjet>

When I try to get value for the node:

"com:myObject/@help"

I've got "12".

But my problem is when I try to get value for nodes:

"com:myObjet/@ref:label" or "com:myObject/@type:cen"

I've got no result. So I believe it comes from the namespace, but I'm not sure. I've declared the namespaces in my XSL file also.

I use the jaxp-api.1.4.2 plugin.

Upvotes: 0

Views: 28

Answers (1)

user2177304
user2177304

Reputation:

com:myObjet/@ref:label

and

com:myObject/@type:cen

return nothing because myObject does not have those attributes. They belong to myNode.

//com:myNode/@ref:label

returns the expected value. Note that xpaths are evaluated in context, so depending on where you execute the xpath from you may need to include the leading //.

Upvotes: 1

Related Questions