This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Expression Logic Problem
- From: "Renick, Garrel" <garrel at more dot net>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 31 Jul 2002 12:43:14 -0500
- Subject: [xsl] Expression Logic Problem
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hello. I'm trying to solve an expression logic problem and I'm stumped.
I'm trying to determine if the context node I'm matching in a
template is the first element. If it is, I want to prepend
some information. If it isn't first, I just want to display the
data. However, it seems as though every element matches my
expression that tries to determine if the element is first.
If someone could help me understand my delimma, I'd greatly
appreciate it. Here is a sample of my data and my template:
My data:
<document>
<configure>
<server>
<resultfield id="100">Snow White</resultfield>
<resultfield id="50">Mickey Mouse</resultfield>
</server>
</configure>
<record>
<field id="100">Snow White and the Seven Dwarfs</field>
<field id="100">A story about some dwarves and their friend</field>
<field id="50">Fantasia</field>
<record>
</document>
My Template:
<xsl:template match="field">
<xsl:variable name="id" select="@id"/>
<xsl:choose>
<!-- when the ID of the resultfield returned by the server matches
the ID of a resultfield to display in the configuration data
and it is the first one, display the resultfield value and precede
it with the display name from the configuration data. If it isn't
first, just display the resultfield value
-->
<xsl:when test="/document/configure/server/resultfield/@id=$id">
<xsl:if test="self::node()[1]">
<!-- I've also tried position()=1 here without success -->
<xsl:value-of select="/document/configure/server/resultfield[@id=$id]"/>:
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="."/>
<br/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>
The data I expect and want:
Snow White: Snow White and the Seven Dwarfs
A story about some dwarves and their friend
Mickey Mouse: Fantasia
The data I get:
Snow White: Snow White and the Seven Dwarfs
Snow White: A story about some dwarves and their friend
Mickey Mouse: Fantasia
Regards,
Garrel Renick
garrel@more.net
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list