Subject: Re: Re: <xsl:choose> or variable syntax incorrect?
From: Brook Ellingwood <brook@xxxxxxxxxxx>
Date: Fri, 26 Sep 2003 13:02:48 -0700
|
Ah. I missed something. It's just an XPath fix, as I wasn't looking for the
right element:
<xsl:when test ="boards/board">
Incidentally, I like Tom's approach of just assigning the color to a
variable better than mine. And he's right about the HTML.
-- Brook
> From: "Kathy Burke" <Kathy_Burke@xxxxxxxxx>
> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Date: Fri, 26 Sep 2003 15:25:57 -0400
> To: "'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Subject: RE: Re: <xsl:choose> or variable syntax incorrect?
>
> Thanks Brook, that certainly is less complex! I'm using a very simple test
> xml file with three <Station> elements, 2 have <Board>s, 1 doesn't. My test,
> however, still results in the <otherwise> -- blue row for all 3 <Stations>.
> My xml:
>
> <Station name='StationOne'>
> <Boards>
> <Board sn='123'/>
> <Board sn='124'/>
> </Boards>
> </Station>
>
> <Station name='StationTwo'>
> <Boards>
> <Board sn='125'/>
> </Boards>
> </Station>
>
> <Station name='StationThree'>
> <Boards>
> </Boards>
> </Station>
>
> Thanks for responding. Kathy
>
> -----Original Message-----
> From: Brook Ellingwood [mailto:brook@xxxxxxxxxxx]
> Sent: Friday, September 26, 2003 3:07 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: Re: <xsl:choose> or variable syntax incorrect?
>
>
> Okay, I haven't followed this whole thread but when I parse your code in
> your last mail, I see that you have unclosed <tr> tags. Aside from that, it
> seems to me that you are making a simple boolean test way too complex:
>
> Try this:
>
> <xsl:template match="Station">
> <xsl:choose>
> <xsl:when test ="./boards">
> <tr bgcolor="red" valign="middle">
> <td><xsl:value-of select="@name"/></td>
> </tr>
> </xsl:when>
> <xsl:otherwise>
> <tr bgcolor="navy" valign="middle">
> <td><xsl:value-of select="@name"/></td>
> </tr>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> Hope that helps.
>
> -- Brook
>
>
>> From: "Kathy Burke" <Kathy_Burke@xxxxxxxxx>
>> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> Date: Fri, 26 Sep 2003 14:38:06 -0400
>> To: "'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
>> Subject: RE: Re: <xsl:choose> or variable syntax incorrect?
>>
>> First, I truly appreciate your responding. But please tell me how I did
> not
>> "explain the problem I've solving"? I honestly thought I did!
>>
>> <station name='StationOne'>
>> <boards>
>> <board sn='123'/>
>> <board sn='124'/>
>> </boards>
>> </station>
>>
>> If there are no <board> elements in the <station> element, I would like to
>> have a blue row with the value-of the <station> name attribute as text:
>>
>> -----------------------------------
>> Station One (in red text)
>> -----------------------------------
>>
>> Otherwise, I would like the same text (Station One) but in a blue row.
>>
>> I still don't understand why this doesn't work:
>>
>> <xsl:template match="Station">
>>
>> <xsl:variable name="boards"
> select="//Station[name='@name']/Boards/Board"/>
>> //to select the boards under the specific station for each node?
>>
>> <xsl:variable name="nboards" select="count($boards)" />
>> //to count the result of the nodeset above?
>>
>> <xsl:choose>
>> <xsl:when test="$nboards < 1"> //if variable is < 1 (or empty)
>> <tr bgcolor="navy" valign="middle"> //create a blue row
>> <td><xsl:value-of select="@name"/></td> //put the name attribute text here
>> </xsl:when>
>> <xsl:otherwise>
>> <tr bgcolor="red" valign="middle"> //otherwise, create a red row
>> <td><xsl:value-of select="@name"/></td>
>> </xsl:otherwise>
>> </xsl:choose>
>>
>> Although it doesn't work, why is it SO dreadful? If I could correctly
> return
>> the variant I need (are there boards for this station?) wouldn't the rest
> be
>> ok?
>>
>> I came up with this either out of books or from the MANY examples I've
> read
>> on the newsgroups.
>>
>> I have read Jeni's book (and M. Kay's as well). Unfortunately, that
> doesn't
>> mean I've absorbed it all :-?
>>
>> If you, or anyone, could please point me to an example of what I've
>> described, I would truly appreciate it.
>>
>> Thanks again.
>>
>> Kathy
>>
>>
>> -----Original Message-----
>> From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx]
>> Sent: Friday, September 26, 2003 2:29 PM
>> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> Subject: Re: <xsl:choose> or variable syntax incorrect?
>>
>>
>>
>> "Kathy Burke" <Kathy_Burke@xxxxxxxxx> wrote in message
>>
> news:395DE57EA5BB7F4E952B7B89775350B5021E4208@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>> Same problem...but perhaps not the variable name issue? I've used the
>>> current() syntax per Dimitri. Again, I'm trying to get a navy row if the
>>> when test < 1 count, otherwise red. My xml source has three <Station>
>>> elements, 2 have <Board> elements, 1 does not. However, all rows remain
>>> navy. Any other comments on where I could be gong astray with the
>> following?
>>
>> You could be going astray almost everywhere -- the code full of weird
> things
>> to me.
>>
>>>
>>> <xsl:template match="Station">
>>>
>>> <xsl:variable name="boards"
>> select="//Station[current()/@name]/Boards/Board"
>>> />
>>
>> ^^^^^^^^^^^^^^^^^
>>
>> Are you sure you really *mean* this? This predicate is true if the current
>> node has a "name" attribute (which is probably always the case).
>>
>>
>>> <xsl:variable name="nboards" select="count($boards)" />
>>
>> Because you're later testing to see if the count is less than one or not,
>> you do not need the count at all. You just need whether the nodeset is
> empty
>> or not -- this happens to be the expression
>>
>> $boards
>>
>> itself.
>>
>>>
>>> <xsl:choose>
>>>
>>> <xsl:when test="$nboards < 1">
>>> <tr bgcolor="navy" valign="middle">
>>> <td><xsl:value-of select="@name"/></td>
>>> </xsl:when>
>>>
>>> <xsl:otherwise>
>>> <tr bgcolor="red" valign="middle">
>>> <td><xsl:value-of select="@name"/></td>
>>> </xsl:otherwise>
>>>
>>> </xsl:choose>
>>
>>
>> This test seems also very strange for generating rows with alternating
>> properties, but you haven't at all explained the problem you're solving,
> so
>> it is difficult to say that what you're doing is just wrong.
>>
>>
>> I strongly recommend reading a good introductory book on XSLT -- e.g.
>> Jeni's:
>>
>> "Beginning XSLT"
>>
>> for everyone, who needs to start understanding some basic concepts and
>> techniques in writing XSLT transformations.
>>
>>
>> =====
>> Cheers,
>>
>> Dimitre Novatchev.
>> http://fxsl.sourceforge.net/ -- the home of FXSL
>>
>>
>>
>>
>> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>>
>>
>>
>> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>>
>>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- Re: Re: <xsl:choose> or variable syntax incorrect?, (continued)
- Dimitre Novatchev - Fri, 26 Sep 2003 15:35:17 -0400 (EDT)
- David Carlisle - Sat, 27 Sep 2003 05:07:04 -0400 (EDT)
- Passin, Tom - Fri, 26 Sep 2003 15:20:31 -0400 (EDT)
- Kathy Burke - Fri, 26 Sep 2003 15:26:16 -0400 (EDT)
- Brook Ellingwood - Fri, 26 Sep 2003 16:02:58 -0400 (EDT) <=
- Passin, Tom - Fri, 26 Sep 2003 15:35:08 -0400 (EDT)
- John Reid - Sat, 27 Sep 2003 22:11:41 -0400 (EDT)
- Kathy Burke - Fri, 26 Sep 2003 15:49:00 -0400 (EDT)
|
|