This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Nested/embedded/self-referential path expressions.
- From: "Edward L. Knoll" <ed dot knoll at cosd dot fedex dot com>
- To: Jeni Tennison <jeni at jenitennison dot com>
- Cc: XSL Post <XSL-List at lists dot mulberrytech dot com>
- Date: Thu, 11 Jul 2002 16:04:16 -0600
- Subject: Re: [xsl] Nested/embedded/self-referential path expressions.
- Organization: WSCR
- References: <3D2DD04C.1F7622FB@cosd.fedex.com> <134462956536.20020711212008@jenitennison.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Jeni Tennison wrote:
>
> Hi Ed,
>
> > What I want to do is combine the if with the "match=..." clause of
> > the template. The problem is that I need to reference the "name()"
> > of the context/element with the "name()" in a different
> > context/element. The logical expression would be somethink like the
> > following:
> >
> > <xsl:template match="Row/*[/Table/Columns/*[{inner context name}={outer
> > context name}]]">
> >
> > Can/how do I reference a element/component of the outer context for
> > comparison in the inner context?
>
> You can't. One method you can use in this situation, though, is to
> define a key that can get you from a name to a column (child of the
> Columns element):
>
> <xsl:key name="columns" match="/Table/Columns/*" use="name()" />
>
> Then you can do:
>
> <xsl:template match="Row/*[key('columns', name())]">
> ...
> </xsl:template>
>
> In general it's a bad idea to use complicated conditions like this
> within patterns; you'd probably be better off having a general
> template for all elements within Row elements, but only applying
> templates to those that share a name with a column:
>
> <xsl:template match="Row">
> <xsl:apply-templates select="*[key('columns', name())]" />
> </xsl:template>
>
> <xsl:template match="Row/*">
> ...
> </xsl:template>
Seems as though the pattern in the "select" is darn near as complex as
the match: "*[key('columns', name())]" versus "Row/*[key('columns',
name())]". Did we actually gain much ground here? Are there underlying
reasons why complexity in the "select" is preferred over the "match"?
What I decided to do (although I may change given your feedback) is two
templates and modes: one template to filter the columns, other templates
to process the filtered nodes:
<xsl:templateatch="gnsl:Row/*">
<xsl:variable name="MyName" select="name()" />
<xsl:if test="$TableColumns[name()=$MyName]" >
<xsl:apply-templates select="." mode="ColumnContent" />
</xsl:if>
</xsl:template>
<xsl:template mode="ColumnContent" match="gnsl:Row/*>
....
</xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list