[xsl] Variable scope when using imported stylesheets

Subject: [xsl] Variable scope when using imported stylesheets
From: Ralph Holz <ralph.holz@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 Aug 2004 15:47:40 +0200
Hi,

I'm a bit at a loss how I can use variables in the context of imported stylesheets. I have a stylesheet A that worked standalone up to now, but now needs to import templates from a stylesheet B.

I had defined global variables in A to save myself some typing: they selected some nodesets *deep* in the source tree that I needed very often in the processing, e.g. (simplified)

<xsl:variable
  name="VehData"
  select="/root/data/baseDboFileRef/FileRefEval/FileRefVehData"
/>

I used $VehData whenever I needed to access the "vehicle data". Fine as long as there is only one baseDboFileRef.

But my *new* source tree is going to have several ones, which are treated with the templates from the imported stylesheet:

<xsl:for-each select="/root/data/baseDboFileRef">
  <xsl:call-template name="[...]" />
  ... many more templates from B called ...
</xsl:for-each>

I would like to define variables again to save the typing, so I thought I would need relative paths in the variable to make the access independent of the changing context (baseDboFileRef).

First, I tried defining global variables in the imported stylesheet that were an abbreviated version, as a tribute to the changed context:

<xsl:variable
  name="ImpVehData"
  select="FileRefEval/FileRefVehData"
/>

I didn't have much hope that that would work and indeed it didn't...

Now I could define my variables within each of the templates that get imported and I guess that would work. But since there are so many templates I'm wondering if there is a more elegant way to do this?

Thanks,
Ralph

Current Thread