Subject: Re: [xsl] starts-with on more than one item From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Mon, 02 Jun 2008 11:49:41 -0400 |
glad you got it working, just one comment,
<xsl:choose> <xsl:when test="position()=last()"> <xsl:value-of select="concat(', and ', ., '.')"/> </xsl:when> <xsl:when test="position()=1"> <xsl:value-of select="concat(' ', .)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(', ', .)"/> </xsl:otherwise> </xsl:choose>
swap the first two when clauses, otherwise you'll get an ", and" on a list of length 1.
If it wasn't for the and you could replace the whole for-each by
<xsl:value-of select="$names" separator=", "/>
It's probably possible to use a trick xpath to get the same effect with a single value-of, but it's probably more maintainable to use the for-each form that you have in this case.
<xsl:choose> <xsl:when test="position() = 1"> <xsl:text> </xsl:text> <xsl:otherwise> <xsl:when test="position()=last()"> <xsl:if test="position() > 2"> <xsl:text>,</xsl:text> </xsl:if> <xsl:text> and </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>, </xsl:text> </xsl:otherwise> </xsl:choose> <xsl:value-of select="."/>
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Help in extracting namesp, Enrico . Raymund | Thread | Re: [xsl] starts-with on more than , David Carlisle |
Re: [xsl] Directory listing, as xml, Michael Ludwig | Date | Re: [xsl] starts-with on more than , David Carlisle |
Month |