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

Re: check if document exists

Subject: Re: check if document exists
From: "Todd Baker" <pixelboy@xxxxxxxxx>
Date: Tue, 25 Jul 2006 17:28:50 +1000
xsl document exists
Thanks for the help guys.

I suspected Id need an extension function but hoped there was another
solution.

Thanks again.

On 25/07/06, Albert Juhi <albertjuhe@xxxxxxxxx> wrote:
Hi,

I've had a similar problem, I needed to test an image file exists and
if exists I needed width and height.

My solution is with Java, I can't find another way to resolve it.

<xsl:template name="file-exists" xmlns:file="java.io.File">
   <xsl:param name="filename"/>
   <xsl:value-of select="file:exists(file:new($filename))"/>
 </xsl:template>



<xsl:template name="image-size"
xmlns:java="xalan://javax.swing.ImageIcon">
   <xsl:param name="mida" select="'width'"/>
   <xsl:param name="filename"/>

  <xsl:if test="normalize-space($filename)">
    <xsl:variable name="imatge" select="java:new($filename)"/>
     <!-- Extract image file info -->
     <xsl:choose>
     <xsl:when test="$mida='width'">
      <xsl:value-of select="java:getIconWidth($imatge)"/>
     </xsl:when>
     <xsl:when test="$mida='height'">
      <xsl:value-of select="java:getIconHeight($imatge)"/>
     </xsl:when>
     <xsl:when test="$mida='mida'">
      <xsl:value-of
select="java:getIconHeight($imatge)*java:getIconWidth($imatge)"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="-1"/>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:if>
 </xsl:template>


Albert Juhi www.omaonk.com

2006/7/24, Todd Baker <pixelboy@xxxxxxxxx>:
> I am having a similar problem in xslt 1.0 (MSXML).
>
> We have a supplier ftp'ing some XML data but sometimes it doesnt
> arrive and sometimes its invalid XML :(
>
> Ive tried
>
> <xsl:if test="msxsl:node-set(document('..\weather\weather.xml'))">
> and
> <xsl:if test="document('..\weather\weather.xml')">
>
> but both throw errors and the template stops.
>
> Is there any way I can test the validity of the document to be
> imported and handle it gracefully?
>
> Cheers
>
> Cheers




--
Todd Baker
http://electronet.com.au - Where electrons go for a good time!

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.