aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to get relative path specified in Entity declaration in DTD? 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 "How to get relative path specified in Entity declaration in DTD?" Watch "How to get relative path specified in Entity declaration in DTD?" New topic
Author

How to get relative path specified in Entity declaration in DTD?

R Firoz
Greenhorn

Joined: Aug 28, 2007
Posts: 8
unparsed-entity-uri() returns the resolved path rather than keeping the relative path specified in the Entity declaration.

For example:

If the following is declared in DTD:

<!Entity p SYSTEM "xyz\pic.jpg">

and transformer is run from c:\temp\data folder, unparsed-entity-uri(p) returns file://c:\temp\data\xyz\pic.jpg.

Is there a way to keep the relative path specified in the Entity element either through xsl or transformation?
Or how would you get "xyz\pic.jpg"

Any help is greatly appreciated.

Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

If you want to get the entity as it is declared, just use the entity. Just don't call unparsed-entity-uri.

(You didn't explain why you chose to use the unparsed-entity-uri function...)
R Firoz
Greenhorn

Joined: Aug 28, 2007
Posts: 8
Thanks Paul for replying, but I'm using the unparsed-entity-uri to get the value. However, it appends the path from where the transformation is run. How else could I do that in xsl? Is there any other function that I can call and get the relative path that is specified in the entity?

Thanks,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

R Firoz wrote:Thanks Paul for replying, but I'm using the unparsed-entity-uri to get the value.

Yes, you said that.
However, it appends the path from where the transformation is run.

Yes, you said that.
How else could I do that in xsl? Is there any other function that I can call and get the relative path that is specified in the entity?

You didn't explain why just using the entity itself wouldn't get the value specified by the entity. In fact it looks like you didn't read what I posted at all, you just posted your question over again.
R Firoz
Greenhorn

Joined: Aug 28, 2007
Posts: 8
Sorry Paul. I should have been more clear about the question. I think an example might clarify things.

I have the following xml



How can I get the value (relative path) of mypicture in xsl?

I'm not that advance in xsl stuff so I'm sorry I don't know what you mean by:
using the entity itself wouldn't get the value specified by the entity


An example with the above code might help.

Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Ah, I see. You are asking about an unparsed entity, which wasn't what you showed in your original post. The example I had in mind for "using the entity itself" was like this:

But I was thinking of an internal entry, so that wouldn't work for you.

However now that I understand your question properly, I don't understand why you are asking it. What possible use can you have for a relative URL? (Especially since the one you posted is malformed.)
R Firoz
Greenhorn

Joined: Aug 28, 2007
Posts: 8
I need to create HTML output and

Found a similar scenario explained here in Using entityref: http://www.sagehill.net/docbookxsl/GraphicsLocations.html

Just quoting part of it here:


Absolute paths in HTML src attributes are a problem if you put the HTML files on a webserver. It is likely the absolute path will not match the document root of the HTTP server, so such references will result in missing graphics when the HTML file is viewed. Relative paths are preferred, but there is no way to get relative paths when using entityref. For this reason, the img.src.path parameter has no effect on entityref paths, because it cannot be prepended to absolute paths.

However, if you put your entity declarations in a separate file, and use an XML catalog to find the declarations file, then you can substitute different pathnames at runtime by using a different catalog. For example, if you move the above entity declaration to a file named mygraphics.ent, you can reference it as follows:


This arrangement uses a parameter entity to specify the location of the file containing the declarations, then it immediately uses a parameter entity reference %graphicset; to pull in the file's contents at that point in the DTD.

You can swap declarations files at runtime by using a catalog entry such as the following:



You just need to make sure that your alternate graphics declarations file declares the same set of entity names, and that they resolve to full pathnames that work for the HTML output.


The problem is, I'm working with the authored content and do not have the luxury of moving the entity declaration to a separate file, the solution they offer. I'm looking if it is by any means possible through XSL?

Hope that clarifies the problem.

Thanks,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

It's not clear to me why the entity declaration needs to be in a separate file to enable the use of an XML catalog. In fact it looks to me like putting the entity declaration in a separate file is solving a different problem than the problem being solved by the XML catalog.

It looks to me like the XML catalog is intended to solve the problem I think you have (notice that you are still posting questions about your proposed solution rather than just posting the original question). You don't really need to switch between catalogs, do you?
R Firoz
Greenhorn

Joined: Aug 28, 2007
Posts: 8
It looks to me like the XML catalog is intended to solve the problem I think you have


Yes, it tries to solve the same problem that I have.

However, that solution does not work for me because I have been given the authored xml and there is no way for me to change the xml. So I cannot put the entities in separate file, even to try to see if there solution works. I need to find a way through xsl to get the relative path that is specified at external entity and the only way that I get to that is using unparsed-entity-uri, but that returns the absolute path which I don't want.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

And you tried setting up the catalog while leaving the XML as it is? Perhaps you could explain to me why the entity would have to be declared in a different document to make the catalog work, because I don't see any reason for that. And I don't think that text you posted said that either.
 
jQuery in Action, 2nd edition
 
subject: How to get relative path specified in Entity declaration in DTD?