File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Accessing attribute with colons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Accessing attribute with colons" Watch "Accessing attribute with colons" New topic
Author

Accessing attribute with colons

JPraveen Kumar
Ranch Hand

Joined: Aug 31, 2004
Posts: 80
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
Bartender

Joined: Oct 14, 2005
Posts: 18110
    
    8

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

Joined: Aug 31, 2004
Posts: 80
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
Bartender

Joined: Oct 14, 2005
Posts: 18110
    
    8

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".)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing attribute with colons
 
Similar Threads
XSLT:XML->XML:Auto-Add undesirable xmlns declaraction ..... please help
ID Ref problem
to EXACT Dublicate an xml file[xml->xml] via Java TransformerFactory classes and XSTL well I do not
xsl and xslt
XPath expression