RE: [xsl] multiple input document question

Subject: RE: [xsl] multiple input document question
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 17 Jul 2008 08:45:44 +0100
> I'm wondering if there is any way to do the following:
> 
> <xsl:template match="*[@menu]">
>         <xsl:variable name="id" select="@id"/>
>         <xsl:for-each select="document('f1.xml')/$id"> ...

You're asking us to work out what you want to do by showing us code that
doesn't do it?

Well, we're not psychic, but fortunately we've seen the same mistakes quite
often, and I guess that what you had in mind is that the value of $id is an
element name which you then want to substitute into the path expression.
XSLT doesn't use variables to do textual substitution in the way that a
shell-script language does - variables represent values, not fragments of
expression text. What you want is probably

document('f1.xml')/*[name()=$id]

On the other hand it's possible that $id is not just an element name, but an
entire XPath expression. In that case you either need to use the technique
of generating a stylesheet, or you need an extension such as
saxon:evaluate() - many XSLT processors have an equivalent but it's not in
the standard.

Either way, be careful about namespaces.

Michael Kay
http://www.saxonica.com/

Current Thread