Subject: RE: Looking up elements with {@attname}
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Mon, 24 May 1999 09:54:55 +0100
|
> Klaas Bals [mailto:kbals@xxxxxxxxxxx] asked:
>I'll try to give a simplified example:
>
> <element att2="same-value" att3="firstvalue"/>
> <element att2="same-value" att3="secondvalue"/>
>
> <xsl:stylesheet>
> <xsl:template match="element">
> <xsl:value-of select="@att3"/>
> <xsl:text> found </xsl:text>
> <xsl:value-of select="//element[@att2={./@att2}]/@att3"/>
> </xsl:template>
> </xsl:stylesheet>
>
the curly-bracket notation can only be used in attributes that are defined
to be attribute-value-templates; the select attribute of xsl:value-of (and
all other attributes whose value is an expression) are not AVTs, so you
cannot use this mechanism.
Try:
> <xsl:template match="element">
> <xsl:variable name="x" expr="@att2"/>
> <xsl:value-of select="@att3"/>
> <xsl:text> found </xsl:text>
> <xsl:value-of select="//element[@att2=$x][2]/@att3"/>
> </xsl:template>
I added the [2] because in your example you're looking for the second
element in which att2 has this value: I suspect this isn't quite right but
you haven't specified the problem in enough detail for me to do any better.
Alternatively, and probably more efficiently, use keys.
Mike Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|