xsl-list
[Top] [All Lists]

[xsl] The Oxford Comma - A Gift Worth Atleast 5 Cents

2008-06-19 13:41:23
To my esteemed XSLT developers, I submit this simple gift you you with
humility.  If you ever end up with a variable containing a sequence of
3 or more English words/phrases and want to output good English, paste
this in (just change the variable name to whatever).

I know this is childs play for all you intelligent folks but hey,
maybe it will save someone 10 minutes of typing one day?  Just trying
to give back to the group that is able to deliver the seemingly
impossible..(David)

OUTPUTS: "The services also include Cisco IP phone end user training,
Cisco attendant console operator training, and Cisco call center agent
training."

The services also include
<xsl:for-each select="$trainingnames">
<xsl:choose>
    <xsl:when test="count($trainingnames) > 2">
        <xsl:choose>
        <xsl:when test="position()=1">
            <xsl:value-of select="concat(' ', .,',')"/>
        </xsl:when>
        <xsl:when test="position()=last()">
            <xsl:value-of select="concat(' and ', .,'. ')"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="concat(' ', .,',')"/>
        </xsl:otherwise>
        </xsl:choose>
    </xsl:when>
    <xsl:when test="count($trainingnames) = 2">
        <xsl:choose>
        <xsl:when test="position()=1">
            <xsl:value-of select="concat(' ', .,' and')"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="concat(' ', .,'. ')"/>
        </xsl:otherwise>
        </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="concat(' ', .,'. ')"/>
    </xsl:otherwise>
</xsl:choose>
</xsl:for-each>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--