xsl-list
[Top] [All Lists]

RE: [xsl] Calling a Java extension from XSLT using Saxon B (to check for image existence in XML)

2009-06-23 16:09:59
Many thanks, Ken. You've saved me many additional hours of digging. The
namespace declaration and code brought me back to another example
Michael had posted, and the namespace was key to understanding that
example. The final code is as follows for future searchers (and as long
as @hsrc is not empty, it works as expected--otherwise, it throws the
error XTTE0570: An empty sequence is not allowed as the value of
variable $hsrcUri in built-in template rule):

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
        xmlns:file="http://www.jclark.com/xt/java/java.io.File";
        xmlns:xs="http://www.w3.org/2001/XMLSchema";
        exclude-result-prefixes="xs file" >

<xsl:output method="xml"/>

<xsl:template match="/">
   <xsl:if test="not( function-available('file:exists') and
                      function-available('file:new') )">
     <xsl:message terminate="yes">
       <xsl:text>Required Java file facilities </xsl:text>
       <xsl:text>are not available</xsl:text>
     </xsl:message>
   </xsl:if>
        <xsl:apply-templates />             
</xsl:template>

<xsl:template match="img">
<!-- takes the relative path @hsrc and resolves a full URI based on the
location of the current XML document -->
<xsl:variable name="hsrcUri" select="resolve-uri(@hsrc, base-uri(.))"
as="xs:anyURI"/>
    <xsl:choose>
        <xsl:when test="file:exists(file:new($hsrcUri))">
                <xsl:message><xsl:value-of select="$hsrcUri"/>
exists.</xsl:message>
        </xsl:when>
        <xsl:otherwise>
                <xsl:message><xsl:value-of select="$hsrcUri"/> does not
exist.</xsl:message>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
     
</xsl:stylesheet>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>