[xsl] Referring to imported variable's value in override

Subject: [xsl] Referring to imported variable's value in override
From: "Christian Roth" <roth@xxxxxxxxxxxxxx>
Date: Mon, 29 Mar 2010 17:37:28 +0200
Hello,

can I use the value of an imported variable in its override definition?

My current use-case is defining the value of a variable in a stylesheet
customization layer as "all it already contains, plus those two items".

Naively trying, I first came up with this:

--main.xsl--
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xs="http://www.w3.org/2001/XMLSchema"; exclude-result-prefixes="xs"
  version="2.0">

  <xsl:import href="sub.xsl" />

  <!-- MAIN -->
  <xsl:variable name="test" select="$test, ('c','d')" />

  <xsl:template match="/">
    <xsl:message select="$test"/>
  </xsl:template>

</xsl:stylesheet>
--end--

--sub.xsl--
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xs="http://www.w3.org/2001/XMLSchema"; exclude-result-prefixes="xs"
  version="2.0">

  <!-- SUB -->
  <xsl:variable name="test" select="('a','b')"/>


</xsl:stylesheet>
--end--

, thinking that the declaration of test in main would use the imported
declaration from sub.xsl since the one in main.xsl does not yet exist at
that position. However, this gives me circular reference error in main.xsl:

SystemID: /Users/chris/Beruf/infinity-loop/testdata/feature-testing/
stylesheet-levels/main.xsl
Severity: fatal
Description: Circular definition of variable test
Start location: 9:0
URL: http://www.w3.org/TR/xslt20/#err-XTDE0640


The desired output in the console would be

--desired output--
a b c d
--end--

How does one best tackle this? Maybe define the base variable with a
different name, say, "test-base" in the imported stylesheet, so that
there is no name-clash resp. override happening? How to do this when
there are more customization layers to handle, each one wishing to refer
to "what's already there"?


Regards
Christian

Current Thread