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

Expression Logic Problem

Subject: Expression Logic Problem
From: "Renick, Garrel" <garrel@xxxxxxxx>
Date: Wed, 31 Jul 2002 12:43:14 -0500
thanksgiving logic problems
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@xxxxxxxx   

 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.