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 XSLT in XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT in XML" Watch "XSLT in XML" New topic
Author

XSLT in XML

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 321

Hello,

I've a .xml and .xsl file.
How to specify xslt path in XML

I've written the following statement in my xml file :-


But I get below error when opened in Opera

This document had no style information.


Please advise.


Thanks,
Pramod
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

The "href" attribute should be a URL. A Windows file path is not a URL. And even if you did make it a file:// URL the chances are that a browser would reject it on security grounds. Your best bet is to make the URL a relative one, that should be relative to the URL where the XML document was loaded from.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 321

Hi Paul,

How to make a file path as a relative url ?

My xml file path is : - C:\Users\Pramod\Desktop\1.xml
and xsl is :- C:\Users\Pramod\Desktop\cdcatalog.xsl

Could you please give me some example.

I tried out few combinations but nothing worked out.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

pramod talekar wrote:How to make a file path as a relative url ?

My xml file path is : - C:\Users\Pramod\Desktop\1.xml
and xsl is :- C:\Users\Pramod\Desktop\cdcatalog.xsl

Could you please give me some example.


Well, "some example" isn't what you are asking for, right? You start with the directory of the XML file. That's your base directory as far as the browser is concerned. (Sort of like the current working directory.) Then the relative URL of the XSL file is the path relative to that base directory. Also remember that you don't use backslashes in a URL.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 321

Hi Paul,

So is it <?xml-stylesheet type="text\xsl" href="C:/Users/Pramod/Desktop/cdcatalog.xsl"?>

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

No. As I said before, that isn't a URL. You must have overlooked that.

Let's take it one small step at a time. What's the base directory for your XML document?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 321

My base directory is "C:/Users/Pramod/Desktop/".
Both files are kept on Desktop. I read somewhere that if both the xml and xslt files share the same path then it's not needed to mention the full path name in xsl:stylesheet.
So I tried writing href="cdcatalog.xsl" & "/cdcatalog.xsl" but it didn't work.
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 513
Hi,

<?xml-stylesheet type="text\xsl" href="cdcatalog.xsl"?>


Try "text/xsl" instead. forward slash instead of backward one.

regards,
Amit
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 321

Amit, You Rock !!
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 513
Hello,
Thanks but no thanks.
This came to the rescue. Check here.

Regards,
Amit
 
GeeCON Prague 2014
 
subject: XSLT in XML