[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
xsl context
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.