This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Parsing a character string
- To: xsl-list at lists dot mulberrytech dot com
- Subject: RE: [xsl] Parsing a character string
- From: Don Bruey <dbruey at CreativeSolutions dot com>
- Date: Thu, 1 Mar 2001 08:33:32 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
Following up on my own post yesterday, here is the two-character solution
given XML:
<?xml version="1.0"?>
<days>
<deliverOnDays>NYNYYYN</deliverOnDays>
</days>
XSL:
--------------------------------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:variable name="weekDays" select="'S M T W ThF Sa'" />
<xsl:template name="parseYNFlags">
<xsl:param name="YNFlags"/>
<xsl:param name="dayAbbreviations" />
<xsl:choose>
<xsl:when test="substring($YNFlags, 1, 1) = 'Y'" >
<xsl:value-of select="substring($dayAbbreviations, 1, 2)" />
</xsl:when>
<xsl:otherwise>_</xsl:otherwise>
</xsl:choose>
<xsl:if test="string-length($YNFlags) > 1" >
<xsl:call-template name="parseYNFlags">
<xsl:with-param name="YNFlags" select="substring($YNFlags, 2)" />
<xsl:with-param name="dayAbbreviations"
select="substring($dayAbbreviations, 3)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="deliverOnDays">
<xsl:variable name="temp" >
<xsl:call-template name="parseYNFlags" >
<xsl:with-param name="YNFlags" select="." />
<xsl:with-param name="dayAbbreviations" select="$weekDays" />
</xsl:call-template>
</xsl:variable>
<!-- now get rid of extra spaces from result -->
<xsl:variable name="translatedTemp" select="translate($temp, ' ', '')" />
<xsl:value-of select="$translatedTemp" />
</xsl:template>
</xsl:stylesheet>
>-----Original Message-----
>From: Scott Downie [mailto:sdownie@euronetworldwide.com]
>Sent: Wednesday, February 28, 2001 2:31 PM
>To: xsl-list@lists.mulberrytech.com
>Subject: [xsl] Parsing a character string
>The input consists
>of seven-character strings that represent the days of the week. One such
>string
>looks like <<YNYNYYN>>. The first character tells me that, "Yes, the system
>is
>to send an alert on Sunday," the second tells me, "No, don't send an alert
>on
>Monday," and so on down through the days of the week. Here is some XML:
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list