RE: if-questioning between two nodes inside an for-each-loop

Subject: RE: if-questioning between two nodes inside an for-each-loop
From: Don Bruey <dbruey@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Sep 2000 09:52:42 -0400
Following XSL works for me in Saxon:
Note two things: 

<xsl:if test=". = $CHOOSE"> not ".=CHOOSE" - you want to reference the
variable you created above. 

Also the <xsl:attribute line is AFTER the value of the element has been
output, which doesn't work.  Move it before the value of the element.  As
you're transforming HTML from XML tag, text, /tag, etc. the XSL processor
can't reasonably expected (I don't think) to be able to go backwards and add
the attribute value to the opening tag. 


<?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:if test=". = $CHOOSE">
			    <xsl:attribute name="selected">
			    </xsl:attribute>
		    </xsl:if>
	    	<xsl:attribute name="value">
	     	 <xsl:value-of select="."/>
	   	 </xsl:attribute>

	   	 <xsl:value-of select="."/>
		  
	 	 </option>

	</xsl:for-each>
          </select>
       </body>
     </html>
  </xsl:template>
</xsl:transform>


Hi all,

i have the following problem:
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


      


 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