• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing attribute with colons

 
JPraveen Kumar
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to retreive an attribute which has a colon in the name.

XML looks like

XSLT looks like

When I run the xslt I get Error in XPath, invalid prefix. Can somebody help me access this please.


Thanks Praveen.
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the sample of your input XML document you left out the part where it declares the namespace whose prefix is "c:" in that document.

It isn't the case that the name of the attribute "contains a colon", from the XML point of view. It is the case that the attribute's name is in a certain namespace, and you have declared that in this document, that namespace will be described by the prefix "c:".

So if you want to search for attributes in that namespace, you have to declare the namespace. That means that in your XSLT document, you have to declare that namespace and specify that its prefix will be "c:" in the XSLT document as well.
 
JPraveen Kumar
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I am not generating the xml here, its the output of a tool that I am using. I am pasting the file here. Please let me know if there s any way that I can get the value myName and the type of the element from this file.

(I am adding space after each colon to avoid the smileys)


Thanks Praveen.

 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I already said. Here's your namespace declaration:Include that declaration in your XSLT as well.

(If you scroll down when posting you'll see the checkbox "Disable smilies in this post".)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic