Show image in Authoring mode

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Fri Jul 18, 2008 1:13 pm

Sorin,

I am unfortunately not able to make it work as i would like to. Did you have a chance to test the code i sent and make it work using the new base-uri function?

Tx.,

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Fri Jul 18, 2008 5:36 pm

Hello Raphael,

The CSS base-uri() function was implemented in Oxygen/Author version 9.3. The following XPath expression that you use in your XSLT stylesheet:

Code: Select all

resolve-uri(concat('images/',@name),base-uri())
has the following CSS equivalent:

Code: Select all

image {
display:block;
content: url(concat(parent-url(base-uri()) "images/" attr(name)));
}
where your chapter element contains an image child element:

Code: Select all


   <chapter id="inline">
<image name="foo.gif"/>
</chapter>
I just tested the following CSS stylesheet applied to your book.xml file in Author 9.3 and the image was displayed correctly in the Author mode of the XML editor panel.

Code: Select all

image {
display:block;
content: url(concat(parent-url(base-uri()) "images/" attr(name)));
}
The parent-url() function is needed because a CSS function resolve-uri() is not implemented yet in Author and your relative path of the image that will be computed relative to the result of base-uri() is the folder name images plus the value of the name attribute. This is the meaning of the XPath expression that you posted and you use in your XSLT stylesheet and for which you need a CSS equivalent.


Regards,
Sorin

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Mon Jul 21, 2008 8:41 am

Sorin,

I have tried the shelfs/book/chapter examples (the one i sent trough via support) and it does not work as expected. The included chapters/loose-chapter.xml does not resolve the a correct image location. The magic i believe would indeed be in the resolve-uri function.
The parent-uri/base-uri combination works for a base like: ../dummy but not for a base uri like ../../

Raphael

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Mon Jul 21, 2008 12:44 pm

Please post small samples of your XML file(s), XSL file and CSS stylesheet or send the sample files and specify the reference to the image file that is not resolved correctly in the Author mode with your sample CSS stylesheet. If you cannot send the complete files just cut small samples from your XML, XSL and CSS files which show the problem. The base-uri() with parent-url() combination works for both a "../dummy" base and for a "../../" base and also works in your example files which you sent by email in the form which I posted above:

Code: Select all

image {
display:block;
content: url(concat(parent-url(base-uri()) "images/" attr(name)));
}
If it does not work for you we need a set of files to see what is not set correctly in your files or if there is another bug in the implementation of base-uri(), parent-url() or other CSS function / element.


Regards,
Sorin

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Mon Jul 21, 2008 1:06 pm

Sorin,

I am referring to the same code i sent earlier with XML files and a particular file structure (see for example http://www.oxygenxml.com/forum/post9983.html#p9983) I can upload it again if needed, shall i use the same URL as before?

tx.,

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Mon Jul 21, 2008 1:12 pm

Yes, please upload your files on the same support page of the website.


Regards,
Sorin

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Fri Jul 25, 2008 3:01 pm

Sorin,

Any feedback available in this "issue" so far?

Thanks(!)

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Fri Jul 25, 2008 5:58 pm

Hello,

For the included file loose-chapter.xml located in folder shelfs/books/sample-book/chapters which has an attribute xml:base="../../" the base-uri() function will return the location of the folder shelfs/books (the folder ../../ computed relative to the location shelfs/books/sample-book/chapters/loose-chapter.xml) and parent-url() will return the location of the folder shelfs. That means foo.gif will be displayed in the Author mode with the CSS that uses content: url(concat(parent-url(base-uri()) "images/" attr(name))); only if you have the image foo.gif in the location shelfs/images/foo.gif. That means both the base-uri() function and the parent-url() function return the expected result. In case of shelfs/books/sample-book/book.xml for the same CSS the image must be in the location shelfs/books/sample-book/images/foo.gif.


Regards,
Sorin

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Fri Jul 25, 2008 6:14 pm

You did not include any foo.gif image file in the zip archive that you sent. For the structure of the directories with XML files and the CSS stylesheet that were included in the zip archive I specified the locations of the image file foo.gif expected by the expresion from the CSS for the two XML files. The expected locations (that is the physical disk locations for which the foo.gif image is actually displayed in the Author mode) show that the implementations of base-uri() and parent-url() are correct.


Regards,
Sorin

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Mon Jul 28, 2008 7:44 am

Sorin,

The idea is that all images for a "book" are in the sample-book/images directory. regardless wether the chapter is inlined or included. This is the orginal problem i have. With XSL that works (if you run the enclosed java demo you will see).

For oXygen to act like this i have to change the base from ../.. to ../WHATEVER; this however breaks the XSL code.

I have uploaded another version this version contains an image.

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Mon Jul 28, 2008 2:43 pm

Hello Raphael,

First of all, the xml:base of the loose-chapter.xml is going down too much. I would use "../" to be at the same level with book.xml.

The problem was caused by the base-uri() function. In case of book.xml, it returned: file:/your-base-dir/sample-books/book.xml. In case of chapters/loose-chapter.xml it returned: file:/your-base-dir/sample-books/.

As you can see, in the first case the filepath pointed to a file and in the second case it pointed to a directory. The CSS parent-url() function called from:

Code: Select all

content: url(concat(parent-url(base-uri())  "images/"  attr(name)));
returned:

file:/your-base-dir/sample-books/ for book.xml
file:/your-base-dir/ for loose-chapter.xml

As you can see the results are different directories, so appending the constant "images" also results in different directories, hence the image cannot be loaded.

A workaround would be to specify for loose-chapter.xml file another xml:base value, pointing to a file, so you should change from:

Code: Select all

<chapter id="seperated" xml:base="../../" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<image name="topbar_logo.png"/>
</chapter>
to:

Code: Select all

<chapter id="seperated" xml:base="../loose-chapter.xml" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<image name="topbar_logo.png"/>
</chapter>
We are also considering changing the url() function to accept more parameters, so you can use it in the CSS like this:

Code: Select all

content: url(base-uri()  "images/"  attr(name));
The url() function would "know" when one of the arguments is a file or a directory and would correctly build the result relative to the first argument. We already tested this and will be available in a next oXygen release.


Regards,
Sorin

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Mon Jul 28, 2008 3:15 pm

Sorin,

Thanks for your response. The problem with changing to ../ or to ../loose-chapter.xml or anything other than ../.. breaks the XSL code (see the included java demo).

For us a solution would be if you would support a resolve-uri function with the same behavior as the one in XPath 2.0.

In the meantime we will manually change the base URI prior to editing and reset it before finishing.

Thanks(!)

Raphael

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Tue Jul 29, 2008 7:21 am

Sorin,

I was trying to better understand why base=../.. is working for me (in XSL, XIncludes and eXist's XML database). I believe this is the reason.

The default base of the loose-chapter.xml is: path/sample-book/chapters/loose-chapter.xml

So .. makes it path/sample-book/chapters/
en then .. makes it path/sample-book/

Then resolving images/foo.gif in XPath works as it performs the following:
path/sample-book/ + images/foo.gif

Hope this helps...

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Tue Jul 29, 2008 10:26 am

Hello,

The expression "../../" is simply not correct for your usage because it does not change the file path as you specified. Please try the following in a stylesheet:

Code: Select all

<xsl:value-of select="resolve-uri('../..', 'file:/path/sample-book/chapters/loose-chapter.xml')"/>
The result is: file:/path/ because each ".." is removing one folder from the path. The filename is not important.

We digged more into the problem, and we found an API incompatibility between the XML parser and Saxon. When using XInclude, the XML parser performs an xml:base fixup, practically recomposing the values for the xml:base attribute, making them relative to the master document. Unfortunately, an XSLT processor does not "know" that the xml:base attributes have already been modified in the first stage by the parser, and uses these values as being relative to the "slave" document.

First of all correct the xml:base from the loose-chapter to "../loose-chapter.xml" (the name is not important, you could use a fix value for all the chapters, let say x.xml which is necessary for the oXygen parent-url() function to work properly).

You can make the XSLT transformation work by applying a cascade of stylesheets: first a copying stylesheet that does not change the source XML file (this will resolve the XInclude references), and then your stylesheet, on the result of the first. The copying stylesheet practically flattens the master file and fixes up the xml:base attributes relative to the master. A copying stylesheet:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

Regards,
Sorin

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Tue Sep 23, 2008 2:30 pm

Sorin,

I have tried you suggestion, but i can't seem to make it work. I first preprocess the XML which "flatens" the xml, it still won't work.
i have changed the xml:base to:

Code: Select all

xml:base="../foo" 
The intermediate flattened XML looks like:

Code: Select all

<shelf xmlns:xi="http://www.w3.org/2001/XInclude">
<?xml-stylesheet type="text/css" href="../../../xsl/wysiwyg.css"?><book xml:base="books/sample-book/book.xml">
<chapter id="inline">
<image name="topbar_logo.png"/>
</chapter>
<chapter id="seperated" xml:base="books/foo">
<image name="topbar_logo.png"/>
</chapter>
</book>
</shelf>
----------
The final result looks like

Code: Select all

<book-shelf>
<tr-book>
<tr-chapter>
<id>inline</id>
<base>books/sample-book/book.xml</base>
<image>books/sample-book/images/topbar_logo.png</image>
</tr-chapter>
<tr-chapter>
<id>seperated</id>
<base>books/sample-book/books/foo</base>
<image>books/sample-book/books/images/topbar_logo.png</image>
</tr-chapter>
</tr-book>
</book-shelf>
i can send the project over again with the suggested solution.

Shouldn't oxygen also perform this base URI fixup (i have it enabled in my preferences).

Radu
Posts: 7107
Joined: Fri Jul 09, 2004 5:18 pm

Re: Show image in Authoring mode

Post by Radu » Tue Sep 23, 2008 3:07 pm

Hi,

Please send the project again to us at our support email address.
http://www.oxygenxml.com/techSupport.html

Thanks,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Dan
Posts: 461
Joined: Mon Feb 03, 2003 10:56 am

Re: Show image in Authoring mode

Post by Dan » Wed Sep 24, 2008 12:38 pm

There is a difference in the way the XML parser resolves the xml:base attributes and the way oXygen does it. In fact it is a bug in Xerces we already reported and we proposed a fix for it.

As a workaround:

1.In the file "loose-chapter.xml" you should move the xml:base attribute from:

<chapter id="seperated" xml:base="../foo">
<image name="topbar_logo.png" />
</chapter>

to the image element, or to another element containing the image (a section for instance):

<chapter id="seperated">
<image name="topbar_logo.png" xml:base="../foo"/>
</chapter>

2.Change your script that starts the Java program adding the oxygen.jar file as first entry in the classpath. The oxygen.jar file can be found in the oXygen installation directory, in the lib subdirectory. You need to do this because oXygen.jar contains some patches for the parser that correct the base-uri fixup. To make sure the patches work correctly, please add to the classpath the xercesImpl.jar file from the same directory.


After this, you should be able to see the images when opening the book.xml file in the Author mode, and will be able to transform it either from oXygen or directly from the command line.

Cheers,
Dan

rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Show image in Authoring mode

Post by rparree » Wed Sep 24, 2008 3:01 pm

Dan,

Thanks for the reply.

I don't have an awful amount of time available today, i did a quick test and it did not work correctly. I guess i do need also the "flatten" part do i (i removed that yesterday from the project and was now trying to solve it just by editing the xml and setting the classpath).

I will have more time tomorrow, i will let you know if it solved the problem.

Tx.,

Raphael

Quintus
Posts: 2
Joined: Tue Jan 26, 2010 12:14 pm

Re: Show image in Authoring mode

Post by Quintus » Tue Jan 26, 2010 2:08 pm

Hello,
I have a question regarding showing images in authoring mode and processing them to pdf.
I looked around and it seems noone had that problem before.
I constructed an example enviroment for a colleague, using xinclude with images in the simplest way possible.
The structure looks like this:

Code: Select all

RootFolder
- MainFile.xml
- Folder 1
- A.xml with pic
- PicturesFolder 1
- picA.png
- Folder 2
- B.xml with pic
- PicturesFolder 2
- picB.png
- Folder 3
- C.xml with pic
- PicturesFolder 3
- picC.png
When I open the main file with xincludes, the first include shows its picture with the correct path of course.
All subsequent pictures are not shown, because obviously the parser has replaced their relative path with the foldername of the first pic (PicturesFolder 1) as xml:base attribute, so the path is messed up, and of course saxon/xalan can't do anything about it either (wether the setting of keep.relative.image.uris is on or not).
sorin wrote: "When using XInclude, the XML parser performs an xml:base fixup, practically recomposing the values for the xml:base attribute, making them relative to the master document."
When I turn that feature off, none of the pictures is found.
I use oXygen 11.1 and wasted half a day to it, what can I do - I do not want to use xml:base attributes in my documents because the whole thing is complicated enough.
(I tried it with xmlmind and there it worked)

Any hints are appreciated.

Regards,
Quintus

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Show image in Authoring mode

Post by sorin_ristache » Tue Jan 26, 2010 6:28 pm

Hello Quintus,
Quintus wrote:The structure looks like this:

Code: Select all

RootFolder
- MainFile.xml
- Folder 1
- A.xml with pic
- PicturesFolder 1
- picA.png
- Folder 2
- B.xml with pic
- PicturesFolder 2
- picB.png
- Folder 3
- C.xml with pic
- PicturesFolder 3
- picC.png
When I open the main file with xincludes, the first include shows its picture with the correct path of course.
All subsequent pictures are not shown

If you do not set an explicit xml:base attribute in your XML files (which means you let the parser do the entire XInclude fixup) and your relative paths are correct (that is in MainFile.xml you include A.xml with the relative path href="Folder_1/A.xml" and in A.xml you include the image with a relative path "PicturesFolder_1/picA.png") then the PNG images should be displayed without problems in Author. I just tested that again in Author. Of course XInclude processing and base URI fix-up must be enabled in Options -> Preferences. They are enabled by default and you should not disable them because you want to include files from different folders.

Do you set an xml:base attribute on an element in your XML files? If yes what is the value of the xml:base attribute and what is the relative path used for including the XML file and the image?

Please send a zip archive with the folder structure and the files that you use for reproducing the problem. You can use the Technical Support page.

Quintus wrote:When I turn that feature off, none of the pictures is found. I use oXygen 11.1 and wasted half a day to it, what can I do - I do not want to use xml:base attributes in my documents because the whole thing is complicated enough.
You should not use xml:base attributes explicitly in your XML documents for such simple cases when the folder structure is known and fixed so that you can reference the included files with the correct relative path. If you turn off base URI fix-up you can be sure the images will not be displayed in Author and they will not be included in the generated PDF output when you run the transformation with a built-in engine of Oxygen (Saxon, Xalan).


Regards,
Sorin

Post Reply