xsl-list
[Top] [All Lists]

Problem using document() to access another XML file

2004-02-20 02:29:00
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
    ============================
    <docs>
        <doc>
            <title>This is Doc 1</title>
            <file type="XLS" size="288.5" unit="Kb">Planning2003.xls</file>
        </doc>
        <doc>
            <title>This is Doc 2</title>
            <file type="PDF" size="700.56"
unit="Kb">annual_report.pdf</file>
        </doc>
        ...
     </docs>

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

     I've got the icons in another XML file

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

     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"
select="document('/formats.xml',/*)/node()"/>
   <xsl:value-of select="$formats/formats/format[(_at_)id=(_dot_)/file/@type]"/>

Case 2:
   <xsl:variable name="format"
select="document('/formats.xml',/*)/node()/formats/format[(_at_)id=(_dot_)/file/@type]"
/>
   <xsl:value-of select="$format"/>

Case 3:
   <xsl:value-of
select="document('/formats.xml',/*)/node()/formats/format[(_at_)id=(_dot_)/file/@type]"
/>

Case 4:
   <xsl:variable name="formatUrl"
select="document('/formats.xml')//format[(_at_)id=(_dot_)/file/@type]"/>
   <img width="32" height="32" border="0">
       <xsl:attribute name="src">
            <xsl:value-of select="$formatUrl"/>
       </xsl:attribute>
   </img>

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

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


************ 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
information.
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
prohibited.
************************************************************************** 



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



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