Subject: RE: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Calling a Java extension , G. Ken Holman | Thread | RE: [xsl] Calling a Java extension , Michael Kay |
Re: [xsl] Calling a Java extension , G. Ken Holman | Date | RE: [xsl] Calling a Java extension , Michael Kay |
Month |