Re: [xslt] suppressing warning from document()



On Tue, Jul 10, 2007 at 12:45:25PM +0100, Sebastian Rahtz wrote:
> I want to load an external file if it exists, otherwise load another 
> file, and so on.
> 
> So in my XSL I do this:
>  
> <xsl:choose>
>           <xsl:when test="boolean(document('sidebar.xml',/))">
>         <xsl:message>found at .</xsl:message>
>           </xsl:when>
>           <xsl:when test="boolean(document('../sidebar.xml',/))">
>         <xsl:message>found at ..</xsl:message>
>           </xsl:when>
>           <xsl:when test="boolean(document('../../sidebar.xml',/))">
>         <xsl:message>found at ../..</xsl:message>
>           </xsl:when>
>         </xsl:choose>
> 
> which works fine, but of course the side effect of the
> first <when> is a message:
> 
>    warning: failed to load external entity "sidebar.xml"
> 
> which is not very nice. Is there any way of avoiding it?

 you need to catch the error message, which should be quite easy
if you code at the C level and at the xsltproc level a --nowarning
option similar to xmllint one should be close to trivial using the
C API.

> or a better method to check if a file exists before
> reading it?

 Not that I can think of, and that's reasonnable, such an XSLT function
would turn into an horrible security hole I'm afraid :-)

> Alternatively, how can I get libxslt to do XInclude processing
> on the XSL itself (as opposed to the input XML)?

  xsltproc does this (--xinclude option), and at the API level
that obviously possible too since xsltproc use the API :-)

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]