Ok, here’s a way using Saxon 9: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:db="http://docbook.org/ns/docbook" xmlns:file="java.io.File" version="2.0">
<xsl:template match="db:imagedata"> <xsl:message><xsl:value-of select="@fileref"/>: <xsl:value-of select="file:exists(file:new(resolve-uri(@fileref, base-uri(.))))"/></xsl:message><!--True if it’s there False if it’s not --> </xsl:template> </xsl:stylesheet> David From: Cramer, David W (David) [mailto:dcra...@motive.com] Sent: Wednesday, October 20, 2010 4:45 PM To: chris snow Cc: docbook@lists.oasis-open.org; Jim Campbell Subject: RE: [docbook] how to throw error if imagedata not found Oops..I wasn’t thinking. That will only work if all your images are svg files…you’ll errors asking it to parse binary files :-) Sorry for the noise, David From: Cramer, David W (David) [mailto:dcra...@motive.com] Sent: Wednesday, October 20, 2010 4:13 PM To: chris snow Cc: docbook@lists.oasis-open.org; Jim Campbell Subject: RE: [docbook] how to throw error if imagedata not found Hi Chris, Btw, I ran across a potentially better answer to your question (depending on the behavior of your xslt processor): http://www.dpawson.co.uk/xsl/sect2/N2602.html#d3859e19 David From: Cramer, David W (David) [mailto:dcra...@motive.com] Sent: Wednesday, October 13, 2010 11:42 AM To: Jim Campbell; chris snow Cc: docbook@lists.oasis-open.org Subject: RE: [docbook] how to throw error if imagedata not found Hi Chris, Here’s what we do: The build runs an xslt that produces a list of images used. Ant then checks to make sure all are the images available and kills with a useful error message the build if any are missing. To avoid an annoying build/fail/fix/repeat cycle, the error message shows all missing images rather than only listing the first missing image it finds. I think to do something like this within the xslt would require that you write an extension/call out to java. David From: jwcampb...@gmail.com [mailto:jwcampb...@gmail.com] On Behalf Of Jim Campbell Sent: Wednesday, October 13, 2010 11:27 AM To: chris snow Cc: docbook@lists.oasis-open.org Subject: Re: [docbook] how to throw error if imagedata not found Hi there, Chris, On Wed, Oct 13, 2010 at 9:16 AM, chris snow <chsnow...@gmail.com<mailto:chsnow...@gmail.com>> wrote: Is it possible for an error to be thrown during processing if a file referred to by imagedata is not found? <mediaobject> <imageobject> <imagedata fileref="../../images/coding-cycle.png"/> </imageobject> </mediaobject> Many thanks, Chris It might not be exactly what you are looking for, but one option would be to include the image via an xinclude mechanism, and then include a xinclude fallback. It might go something like this: <mediaobject> <imageobject> <xi:include fileref="../../images/coding-cycle.png"> <xi:fallback>Image file is unavailable.</xi:fallback> </xi:include> </imageobject> </mediaobject> You would need to use a DTD or schema (or at least a DTD fragment) that allows for use of xinclude. I hope this helps, Jim