[xsl] Re: Conditionally Sum an Attribute

Subject: [xsl] Re: Conditionally Sum an Attribute
From: "Ronnie Royston" <rhroyston@xxxxxxxxx>
Date: Sun, 1 Jun 2008 16:39:52 -0500
Wow! Making a machine speak English is a large problem!!!  Putting
spaces, commas, and a period at the end of a sentence wasn't too bad.
Adding making items plural is a very large problem.  Think about it,
if the word ends with an "h" such as "switch" then it needs an "es" to
be plural.  Some words such as "chassis" and "deer" are both singular
and plural and don't require any "s" or "es".  I guess the easiest
thing is to put a child element under each items <name> called
<plural> and return it if it is preceeded by other than "1 ", but that
gets me back in to an area of complexity that is beyond my reach (for
now).  I'll compromise and remove "chassis" from my list of names.

Actually, an importable stylesheet for making words plural could
probably be made in a week (or year) or two?  Maybe I'll make that a
project - some re-usable XSLT code that I can contribute to the world.
(I hope I said that right).

"DataVox is offering Reuters project services at a fixed price for the
installation of 1007 Cisco phones, 1 Cisco router, 3 Cisco switches,
and 5 Cisco switch linecards."

...close enough for now.

<xsl:for-each select="$names">
<xsl:choose>
       <xsl:when test="position()=1">
		<xsl:choose>
			<xsl:when test="starts-with(current(),'1 ')">
				<xsl:value-of select="concat(' ', .)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="ends-with(current(),'h')">
						<xsl:value-of select="concat(' ', .,'es')"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat(' ', .,'s')"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
       </xsl:when>
       <xsl:when test="position()=last()">
		<xsl:choose>
			<xsl:when test="starts-with(current(),'1 ')">
				<xsl:value-of select="concat(', and ', ., '. ')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="ends-with(current(),'h')">
						<xsl:value-of select="concat(', and ', .,'es','. ')"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat(', and ', .,'s','. ')"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
       </xsl:when>
       <xsl:otherwise>
		<xsl:choose>
			<xsl:when test="starts-with(current(),'1 ')">
				<xsl:value-of select="concat(', ', .)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="ends-with(current(),'h')">
						<xsl:value-of select="concat(', ', .,'es')"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat(', ', .,'s')"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
       </xsl:otherwise>
</xsl:choose>
</xsl:for-each>

Fun stuff...

Current Thread