[xsl] Problem using document() to access another XML file

Subject: [xsl] Problem using document() to access another XML file
From: Aitor San Juan <asanjuan@xxxxxxxxxxxxxx>
Date: Fri, 20 Feb 2004 10:29:00 +0100
Hi all!

    How are things going? I'm stuck with accessing an external document
    from a stylesheet. Read it through and let me know any suggestion,
    hint or idea you might think of to solve this problem.
    I'd be very grateful.
    This my input file: docs.xml
            <title>This is Doc 1</title>
            <file type="XLS" size="288.5" unit="Kb">Planning2003.xls</file>
            <title>This is Doc 2</title>
            <file type="PDF" size="700.56"

     I want to generate an HTML page with the listing of the docs in the
     along with an icon next to each of them which shows the type of file.

     I've got the icons in another XML file

         <format id="XLS">http://www.myserver.com/images/excel.gif</format>

     For each document <doc> I'm processing, I'd like to obtain the URL
     to the icon file of the same type. For example, for the first
     document with title "This is Doc 1" I should generate an <img> HTML
     tag with src attribute: "http://www.myserver.com/images/excel.gif";
     This is what I have tried when accessing "formats.xml", but I'm not
     successful in obtaining the desired result. I know these ways may
     not be very efficient, as I load the formats.xml file for each
     <doc>, but this is the only thing I've been able to think of. Any
     hint or idea would be highly appreciated. Thanks all in advance.

Case 1:
   <xsl:variable name="formats"
   <xsl:value-of select="$formats/formats/format[@id=./file/@type]"/>

Case 2:
   <xsl:variable name="format"
   <xsl:value-of select="$format"/>

Case 3:

Case 4:
   <xsl:variable name="formatUrl"
   <img width="32" height="32" border="0">
       <xsl:attribute name="src">
            <xsl:value-of select="$formatUrl"/>

Case 5:
   <xsl:variable name="formats"
   <img width="32" height="32" border="0">
      <xsl:attribute name="src">
          <xsl:call-template name="getFormatURL">
             <xsl:with-param name="nodes"
             <xsl:with-param name="codFmt" select="string(./file/@type)"/>

   <xsl:template name="getFormatURL">
      <xsl:param name="nodes"/>
      <xsl:param name="codFmt"/>
         <xsl:when test="count($nodes)=0">
            <xsl:value-of select="$nodes"/>
         <xsl:when test="count($nodes)=1 and $nodes[1]='format' and
            <xsl:copy-of select="$nodes[position()=1]/@id"/>
            <xsl:call-template name="getFormatURL">
               <xsl:with-param name="nodes" select="$nodes[position() >
               <xsl:with-param name="codFmt" select="$codFmt"/>

************ LEGEZKO OHARRA / AVISO LEGAL / LEGAL ADVICE *************
Mezu honek isilpeko informazioa gorde dezake, edo jabea duena, edota legez
babestuta dagoena.
Zuri zuzendua ez bada, bidali duenari esan eta ezabatu, inori berbidali
edo gorde gabe,legeak debekatzen duelako mezuak erabiltzea baimenik gabe.
Este mensaje puede contener información confidencial, en propiedad o
legalmente protegida.
Si usted no es el destinatario, le rogamos lo comunique al remitente
y proceda a borrarlo, sin reenviarlo ni conservarlo, ya que su uso no 
autorizado está prohibido legalmente.
This message may contain confidential, proprietary or legally privileged
If you are not the intended recipient of this message, please notify it to
the sender and delete without resending or backing it, as it is legally

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread