[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Calling a Java extension from XSLT using Saxon B (

Subject: RE: Calling a Java extension from XSLT using Saxon B (to check for image existence in XML)
From: "Blaine McNutt (rbmcnutt)" <rbmcnutt@xxxxxxxxx>
Date: Tue, 23 Jun 2009 13:09:28 -0700
RE:  Calling a Java extension from XSLT using Saxon B (
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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.