xsl-list
[Top] [All Lists]

RE: SOLVED! Problem using document() to access another XML file

2004-02-20 04:26:28
I'm very grateful for your detailed explanation.

I've tested what you've suggested (the absolute path to the
'formats.xml' file was right, I just created it there to make
sure it was found).

Your suggestion was:

"document('formats.xml',/)/formats/format[(_at_)id=current()/file/@type]"

so I exactly used the following:

<xsl:variable name="formatURL"
select="document('/formats.xml',/)/formats/format[(_at_)id=current()/file/@type]"
/>

The variable "formatURL" had the empty string when accessing it (from within
the template for <doc>'s). I don't know why.

So, I have adapted your initial suggestion into the following 2 steps and it
works:

1. I load the content of the file

<xsl:variable name="fmtURLs" select="document('/formats.xml',/)"/>

2. I access the node I'm interested in:

<xsl:value-of select="$fmtURLs/formats/format[(_at_)id=current()/file/@type]"/>


Thank you so much.

Have a good week-end.


-----Mensaje original-----
De: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Enviado el: viernes, 20 de febrero de 2004 11:26
Para: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Asunto: Re: [xsl] Problem using document() to access another XML file



document('/formats.xml'

is the formats.xml really at the root of your filesystem (or http server)?
if the file is in the same directory as your main source file, you don't
want that / in front of formats.

',/*)

no need for the * there just the single / node would be enough, you just
need any node in the document, used to get the base uri for the relative
yur in the first argument.

Once you have the right file path to your document you just need to make
sure that you get the Xpaths in the dvariable definition to match up.

For example

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

if you changed that to

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

then it would be the empty set, as
document('formats.xml',/)
is the root node (/) of the document, so

document('formats.xml',/)/node()/

is all the child nodes of that, which is probably just the formats
element.

Then 

document('formats.xml',/)/node()/formats/

is the formats children of the formats element, and there is no such child
so this is the empty node set.

So, you could fix that to be


select="document('formats.xml',/)/formats/format[(_at_)id=(_dot_)/file/@type]

now

document('formats.xml',/)/formats/format

would select al the format elements so



 document('formats.xml',/)/formats/format[(_at_)id=(_dot_)/file/@type]

selects all the format elements whose id attribute is equal to the string
value of the type attribute of a child element called file. No format
element has a child element called file, so the right hand side of the =
acts as the empty string, and no format element has an id attribure with
value "" so no format elements are selected by this filter.

You don't want the file element child of the format element, you want
the file element child of the element that was current at the outer
expression, so that is


"document('formats.xml',/)/formats/format[(_at_)id=current()/file/@type]"

David.


************ 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>
  • RE: SOLVED! Problem using document() to access another XML file, Aitor San Juan <=