This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: if-questioning between two nodes inside an for-each-loop
- To: xsl-list at mulberrytech dot com
- Subject: Re: if-questioning between two nodes inside an for-each-loop
- From: Gary L Peskin <garyp at firstech dot com>
- Date: Fri, 15 Sep 2000 08:16:56 -0700
- Organization: The Firstech Corporation
- References: <2339B88D6AA6D31187A80008C7E6F67230ED37@daemsg01.software-ag.de>
- Reply-To: xsl-list at mulberrytech dot com
"Matthiessen, Armin" wrote:
>
> Hi all,
>
> i have the following problem:
>
> inside from a HTML-side i want show a select box with content from the tags
> "single".
> This box should be a pre-selection to the content of the tag "choose". To
> find out, which
> tag is pre-selected i try it with a if-question between the node in den
> variable-definition
> an the node inside the "for-each"-loop. But i don't get a result from the
> if-clause.
>
> Why?
> How can i get a solution?
>
> xml-part:
>
> <cars>
> <single>BMW</single>
> <single>VW</single>
> <single>MERCEDES</single>
> <single>AUDI</single>
>
> <choose>VW</choose>
> </cars>
>
> xsl-part:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:param name="lang" select="en"/>
> <xsl:template match="/">
>
> <html>
> <head>
> </head>
> <body>
> <h1>The choosed car is:</h1>
> <select name="CARS">
>
> <xsl:variable name="CHOOSE">
> <xsl:value-of select="cars/choose"/>
> </xsl:variable>
>
> <xsl:for-each select="cars/single">
> <option>
> <xsl:attribute name="value">
> <xsl:value-of select="."/>
> </xsl:attribute>
> <xsl:value-of select="."/>
>
> <xsl:if test=". = CHOOSE">
> <xsl:attribute name="selected">
> </xsl:attribute>
> </xsl:if>
> </option>
>
> </xsl:for-each>
> </select>
> </body>
> </html>
> </xsl:template>
> </xsl:transform>
>
> Armin
Armin --
Change
<xsl:value-of select="."/>
<xsl:if test=". = CHOOSE">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
to
<xsl:if test=". = $CHOOSE">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
1. You must specify xsl:attribute immediately after instantiating the
<option> literal result element. After instantiating the <option>
element, xsl:attributes must be specified before any child nodes are
added to the <option> element or they will have no effect. So, you need
to move your <option> element contents, namely the value-of until after
the attribute.
2. Use a $ before CHOOSE to specify that CHOOSE is a variable.
3. To produce well-formed X(HT)ML, the value of the selected attribute
should be "selected". The output method processor should reduce this to
just the attribute name (without a value) when outputting html.
HTH,
Gary
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list