external-graphic

View: New views
7 Messages — Rating Filter:   Alert me  

external-graphic

by Alexandre Moraes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

HI,

    is there a way to check if an image exists and if it true i execute external-graphic.
    Or external graphic can return a value if it didn´t find the imagefile?

Thanks,

Alexandre

RE: external-graphic

by Vladimir Rodimyuk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Alexandre,

I think you should use XSLT extension function to perform this check.
I believe you will find very helpful this post:
http://www.biglist.com/lists/xsl-list/archives/200506/msg00400.html

XSL-FO specification does not contain such functionality (and I think should not because it describes how the document should look).

The formatter on the stage of producing PDF checks whether the referenced image exists in order to put it into the stream. But it just replaces images being missed with default error image.

Respectfully,
Volodymyr Rodymyuk

> -----Original Message-----
> From: www-xsl-fo-request@... [mailto:www-xsl-fo-request@...] On
> Behalf Of axdmoraes
> Sent: Tuesday, September 11, 2007 9:00 PM
> To: www-xsl-fo@...
> Subject: external-graphic
>
>
>
> HI,
>
>     is there a way to check if an image exists and if it true i execute
> external-graphic.
>     Or external graphic can return a value if it didn´t find the
> imagefile?
>
> Thanks,
>
> Alexandre
> --
> View this message in context: http://www.nabble.com/external-graphic-
> tf4424287.html#a12620351
> Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.
>




RE: external-graphic

by Alexandre Moraes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Vladimir for the answers.... I´ll test now...



Vladimir Rodimyuk wrote:
Hi Alexandre,

I think you should use XSLT extension function to perform this check.
I believe you will find very helpful this post:
http://www.biglist.com/lists/xsl-list/archives/200506/msg00400.html

XSL-FO specification does not contain such functionality (and I think should not because it describes how the document should look).

The formatter on the stage of producing PDF checks whether the referenced image exists in order to put it into the stream. But it just replaces images being missed with default error image.

Respectfully,
Volodymyr Rodymyuk

> -----Original Message-----
> From: www-xsl-fo-request@w3.org [mailto:www-xsl-fo-request@w3.org] On
> Behalf Of axdmoraes
> Sent: Tuesday, September 11, 2007 9:00 PM
> To: www-xsl-fo@w3.org
> Subject: external-graphic
>
>
>
> HI,
>
>     is there a way to check if an image exists and if it true i execute
> external-graphic.
>     Or external graphic can return a value if it didn´t find the
> imagefile?
>
> Thanks,
>
> Alexandre
> --
> View this message in context: http://www.nabble.com/external-graphic-
> tf4424287.html#a12620351
> Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.
>



RE: external-graphic

by Alexandre Moraes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

            I tryed this:

          <xsl:variable name="absoluteURI" select="resolve-uri(@src, base-uri(.))" as="xs:anyURI"/>
          But it didn´t work.
          Two errors:
          Error in expression resolve-uri(@src, base-uri(.)): Unknown system function: resolve-uri;
and
          Attribute as is not allowed on this element.

Is there another way to solve this? The file that i need to check is an url.

Thanks,

Alexandre
Vladimir Rodimyuk wrote:
Hi Alexandre,

I think you should use XSLT extension function to perform this check.
I believe you will find very helpful this post:
http://www.biglist.com/lists/xsl-list/archives/200506/msg00400.html

XSL-FO specification does not contain such functionality (and I think should not because it describes how the document should look).

The formatter on the stage of producing PDF checks whether the referenced image exists in order to put it into the stream. But it just replaces images being missed with default error image.

Respectfully,
Volodymyr Rodymyuk

> -----Original Message-----
> From: www-xsl-fo-request@w3.org [mailto:www-xsl-fo-request@w3.org] On
> Behalf Of axdmoraes
> Sent: Tuesday, September 11, 2007 9:00 PM
> To: www-xsl-fo@w3.org
> Subject: external-graphic
>
>
>
> HI,
>
>     is there a way to check if an image exists and if it true i execute
> external-graphic.
>     Or external graphic can return a value if it didn´t find the
> imagefile?
>
> Thanks,
>
> Alexandre
> --
> View this message in context: http://www.nabble.com/external-graphic-
> tf4424287.html#a12620351
> Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.
>



Re: external-graphic

by Tony Graham-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Wed, Sep 12 2007 19:23:29 +0100, alexmoraes@... wrote:

>             I tryed this:
>
>           <xsl:variable name="absoluteURI" select="resolve-uri(@src,
> base-uri(.))" as="xs:anyURI"/>
>           But it didn´t work.
>           Two errors:
>           Error in expression resolve-uri(@src, base-uri(.)): Unknown system
> function: resolve-uri;
> and
>           Attribute as is not allowed on this element.
>
> Is there another way to solve this? The file that i need to check is an url.

What XSLT processor are you using?

resolve-uri() is an XPath 2.0 function, and it appears that you are
using an XSLT 1.0 processor since it doesn't recognise the "as"
attribute.

To use Michael Kay's example in his XSL-List post, you would need a
Java-based XSLT 2.0 processor (such as Michael Kay's 'Saxon').

Regards,


Tony Graham.
======================================================================
Tony.Graham@...   http://www.menteithconsulting.com

Menteith Consulting Ltd             Registered in Ireland - No. 428599
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
----------------------------------------------------------------------
Menteith Consulting -- Understanding how markup works
======================================================================


Re: external-graphic

by Alexandre Moraes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


HI,

 I´m using xep 4.10..

Alexandre

Tony Graham-3 wrote:
On Wed, Sep 12 2007 19:23:29 +0100, alexmoraes@gmail.com wrote:
>             I tryed this:
>
>           <xsl:variable name="absoluteURI" select="resolve-uri(@src,
> base-uri(.))" as="xs:anyURI"/>
>           But it didn´t work.
>           Two errors:
>           Error in expression resolve-uri(@src, base-uri(.)): Unknown system
> function: resolve-uri;
> and
>           Attribute as is not allowed on this element.
>
> Is there another way to solve this? The file that i need to check is an url.

What XSLT processor are you using?

resolve-uri() is an XPath 2.0 function, and it appears that you are
using an XSLT 1.0 processor since it doesn't recognise the "as"
attribute.

To use Michael Kay's example in his XSL-List post, you would need a
Java-based XSLT 2.0 processor (such as Michael Kay's 'Saxon').

Regards,


Tony Graham.
======================================================================
Tony.Graham@MenteithConsulting.com   http://www.menteithconsulting.com

Menteith Consulting Ltd             Registered in Ireland - No. 428599
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
----------------------------------------------------------------------
Menteith Consulting -- Understanding how markup works
======================================================================

RE: external-graphic

by Vladimir Rodimyuk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alexandre,

Well, mea culpa, I posted a link to recipe for Saxon 8 processor which is not used by XEP. The XEP formatter is using Saxon 6.5.

Anyway the posted link is a successor of the thread that does contain a solution for your problem. See here: http://www.biglist.com/lists/xsl-list/archives/200006/msg01332.html

Here is a snippet ready to use.

  <xsl:template name="file.check" xmlns:file="java.io.File" >
    <xsl:param name="filename" />
    <xsl:choose>
      <xsl:when test="function-available('file:new')">
         <xsl:variable name="fileobj"
           select="file:new($filename)" />
         <xsl:choose>
            <xsl:when test="not(file:exists($fileobj))">
                <xsl:value-of select="true()"/>
                <xsl:message>
                  <xsl:text>File name='</xsl:text>
                    <xsl:value-of select="$filename" />
                  <xsl:text>' exists.</xsl:text>
                </xsl:message>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="false()"/>
                <xsl:message>
                  <xsl:text>File name='</xsl:text>
                    <xsl:value-of select="$filename" />
                  <xsl:text>' does not exist.</xsl:text>
                </xsl:message>
            </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>
          <xsl:text>WARNING : unable to call function 'file:new'</xsl:text>
        </xsl:message>
      </xsl:otherwise>
   </xsl:choose>
  </xsl:template>

See attached stylesheet for example how to use it.

Respectfully,
Volodymyr Rodymyuk

> -----Original Message-----
> From: www-xsl-fo-request@... [mailto:www-xsl-fo-request@...] On
> Behalf Of axdmoraes
> Sent: Thursday, September 13, 2007 3:57 PM
> To: www-xsl-fo@...
> Subject: Re: external-graphic
>  I´m using xep 4.10..
> Alexandre
> Tony Graham-3 wrote:
> >>             I tryed this:
> >>
> >>           <xsl:variable name="absoluteURI" select="resolve-uri(@src,
> >> base-uri(.))" as="xs:anyURI"/>
> >>           But it didn´t work.
> > resolve-uri() is an XPath 2.0 function, and it appears that you are
> > using an XSLT 1.0 processor since it doesn't recognise the "as"
> > attribute.
> >
> > To use Michael Kay's example in his XSL-List post, you would need a
> > Java-based XSLT 2.0 processor (such as Michael Kay's 'Saxon').
> >
> > Tony Graham.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:file="java.io.File"
version="1.0">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:variable name="image-url" select="'logo.jpg'"/>
  <!-- <xsl:variable name="image-url" select="'file:///D:/Temp/_XslFo/FileExtension/logo.jpg'"/> -->
  <!-- <xsl:variable name="image-url" select="'http://www.renderx.com/Images/logo.gif'"/> -->

  <xsl:template match="/">
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master margin-right="2.5cm" margin-left="2.5cm" margin-bottom="2cm" margin-top="1cm" page-width="21cm" page-height="29.7cm" master-name="first">
                <fo:region-body margin-top="3cm"/>
                <fo:region-before extent="3cm"/>
                <fo:region-after extent="1.5cm"/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="first">
            <fo:flow flow-name="xsl-region-body">
                <fo:block>
                    <xsl:variable name="exists">
                      <xsl:call-template name="file.check">
                         <xsl:with-param name="filename" select="$image-url"/>
                      </xsl:call-template>
                    </xsl:variable>
                    <xsl:choose>
                      <xsl:when test="$exists=true()">
                        <fo:external-graphic src="url({$image-url})"/>
                      </xsl:when>
                      <xsl:otherwise>NO IMAGE EXIST!</xsl:otherwise>
                    </xsl:choose>
                </fo:block>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template name="file.check">
    <xsl:param name="filename" />
    <xsl:choose>
      <xsl:when test="function-available('file:new')">
         <xsl:variable name="fileobj"
           select="file:new($filename)" />
         <xsl:choose>
            <xsl:when test="not(file:exists($fileobj))">
                <xsl:value-of select="true()"/>
                <xsl:message>
                  <xsl:text>File name='</xsl:text>
                    <xsl:value-of select="$filename" />
                  <xsl:text>' exists.</xsl:text>
                </xsl:message>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="false()"/>
                <xsl:message>
                  <xsl:text>File name='</xsl:text>
                    <xsl:value-of select="$filename" />
                  <xsl:text>' does not exist.</xsl:text>
                </xsl:message>
            </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>
          <xsl:text>WARNING : unable to call function 'file:new'</xsl:text>
        </xsl:message>
      </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
</xsl:stylesheet>