Re: path quesion

Subject: Re: path quesion
From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx>
Date: Fri, 30 Jun 2000 12:00:09 +0100
Stephen, there were two possible interpretations of your request. I assume
you want the more complicated one, that is, where the element you want to
look up may change, i.e. at one point the value of $var may be 'customer/age'
and at another point it may be 'customer/sex'. Below is a solution with the
input files I used :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl=""; >
 <xsl:template match="/">

  <xsl:for-each select="Root/Item">
   Item Key value :<xsl:value-of select="."/><BR />

   <!-- Store the cross reference data -->
   <xsl:variable name="CRData" select="document('twodocs01b.xml')"/>

   <!-- Get the Name value for the current Item -->
   <xsl:variable name="CRElement">Name</xsl:variable>
   Name :

   <!-- Get the Desc value for the current Item -->
   <xsl:variable name="CRElement">Desc</xsl:variable>
   Desc :
   <BR />

The main file contained :

<?xml version="1.0" encoding="ISO-8859-1" ?>

... and the lookup file contained (twodocs01b.xml) :

<?xml version="1.0" encoding="ISO-8859-1" ?>

I did notice that the variable declaration must be done in the way shown,
i.e. don't use a select attribute. I'm afraid I have not checked the
subleties surrounding the reason for this. I imagine some optimisation could
be done, particularly if there are many lookup elements you want to extract
for the same key, perhaps by using another variable to hold just the subtree
of the required key and/or using xsl:key/key().

Inspiration for this came from the FAQ under Document#10.
Nick Browne
Slipstone Ltd

Stephen Kirkham wrote:

> I am processing 2 XML files within a single xsl file. >From one file
> I retreive a path value e.g. 'customer/age', from an element , this value
> is placed in a variable. I then want to look for the 'customer/age'
> element in the 2nd xml file, e.g.
>         variable $var contain the sting 'customer/age'
>      attempt to use this in a path expression for the second document
>     <xsl:value-of select="document('data.xml')/$var" />
> I get the following error
>    org.apache.xalan.xslt.XSLProcessorException: pattern =
> 'document('data.xml')/data/$id'
> thankful for any help
>  XSL-List info and archive:

 XSL-List info and archive:

Current Thread