Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2004, 06:54 PM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create a semi-colon delimited value

Hello,
  I need to create the default "value" attribute for the select box depending on which option values are "selected". So far I can get value=13. What I need is value=1;3. All I need to do is add a semi-colon after the first one. I just don't know how to do that when you can't use counters in XSLT.

 My input is as follows:
<select multiple="true" name="test" >
 <option value="1" selected="selected">one</option>
 <option value="2">two</option>
 <option value="3" selected="selected">three</option>
 <option value="4">four</option>
</select>

Here's my code:
<xsl:choose>
   <xsl:when test="@multiple">
        <xsl:attribute name="value">
          <xsl:for-each select="option[@value and attribute::selected]/@value">
               <xsl:choose>
                       <xsl:when test="$counter &gt 1"></xsl:when>
               <xsl:otherwise>;</xsl:otherwise>
                   </xsl:choose>
                   <xsl:value-of select="."/>
              </xsl:for-each>
       </xsl:attribute>
      </xsl:when>
   <xsl:otherwise>

      <xsl:attribute name="value">
    <xsl:value-of select="option[@value and attribute::selected]/@value"/>
      </xsl:attribute>
   </xsl:otherwise>
 </xsl:choose>
Thanks,
Ralph







 
Old January 14th, 2004, 05:36 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you want a semi-colon delimited list of all selected options you need:
Code:
<xsl:for-each select="option[@value and @selected]">
<xsl:value-of select="@value"/>
<xsl:if test="position() != last()">;</xsl:if>
</xsl:for-each>
I can't see the need for the @multiple test; this only tests for the existence of the attribute by the way, not if it is set to true.

Joe (MVP - xml)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Delimited data MargateFan XSLT 2 May 22nd, 2006 05:10 AM
Tab delimited Split ajindal General .NET 1 April 25th, 2006 08:20 AM
Looking for a good example of a Semi-Bound Form howardb1 Access VBA 0 April 24th, 2006 04:27 PM
(Semi) Automating Mail merge to Word Cryolith Access VBA 0 July 6th, 2003 10:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.