Accessing XSL context - Was: RE: Question

Subject: Accessing XSL context - Was: RE: Question
From: Mike Dierken <mike@xxxxxxxxxxxxxxx>
Date: Thu, 4 Feb 1999 15:21:08 -0800
Paul,
I agree that accessing several context is important.
The full approach I would like to suggest provides for a parameter to
context() which traverses up the 'xsl action' tree. So, context(0) would be
equivalent to '.'

So, do we have a general agreement that this is a real problem?
Currently, there are three approaches that seem to fit the requirements:
(if there are more suggestions, please let us know & provide example XSL)
(also, I am biased toward #3, so please add some pros & cons to these...)

Mike D


==============================
Problem: Accessing XSL context
<CLASS>
  <METHOD name="foo">...</METHOD>
  <METHOD name="bar">...</METHOD>
  <METHOD name="baz">...</METHOD>
  <METHOD name="jaz">...</METHOD>
<DESCRIPTION><METHODREF name="foo"/> is very fooey</DESCRIPTION>
</CLASS>

"foo" is not a globally unique id. I know that it will be unique in the
CLASS however. What I need is to do something like this:

<xsl:template match="METHODREF">
   <xsl:value-of select="ancestor(CLASS)/METHOD[@name=***]">
</xsl:template>

The problem is that at the point of the *** I've lost the context of the
METHODREF and don't have a way to get its @name anymore.


==============================
Solution 1: 'constant()' method
PROS:
Access multiple contexts.
Uses existing concepts.

CONS:
Requires multiple, similar declarations to access different contexts.

EXAMPLE:
<xsl:template match="METHODREF">
  <xsl:constant name="where-am-i" value="{@name}"/>
  <xsl:value-of
select="ancestor(CLASS)/METHOD[@name=constant(where-am-i)]"/>
</xsl:template>

==============================
Solution 2: macros and 'arg()' method
PROS:
Access multiple contexts.
Uses existing concepts.

CONS:
The 'arg()' method isn't currently supported in query strings.
Requires multiple, similar declarations to access different contexts.

EXAMPLE:
<xsl:macro name='helper'>
 <xsl:macro-arg name='where-am-i'/>
  <xsl:value-of select="ancestor(CLASS)/METHOD[@name=arg(where-am-i)]"/>
 </xsl:macro-arg>
</xsl:macro>

<xsl:template match="METHODREF">
 <xsl:invoke macro='helper'>
  <xsl:arg name="where-am-i" value="{@name}"/>
 </xsl:invoke>
</xsl:template>

==============================
Solution 3: 'context()' method
PROS:
Access multiple contexts.
Doesn't require declarations to access different contexts.
More declarative of what you want, rather than how to get it.

CONS:
Introduces new concept.

EXAMPLE:
<xsl:template match="METHODREF">
  <xsl:value-of select="ancestor(CLASS)/METHOD[@name=context(1)/@name]"/>
</xsl:template>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread