[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Parsing a character string

Subject: RE: Parsing a character string
From: Don Bruey <dbruey@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Feb 2001 16:09:03 -0500
parse string xsl
Given a very simple xml document like this:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="days.xsl"?>
<days>
<deliverOnDays>NYNYYYN</deliverOnDays>
</days>


This XSL is a start.  The only changes you'll have to make
are for your HTML output.  Also notice that instead of Th and Sa, you get H
and A.  You
can translate these easy enough once you have the string built. This should
get you 
on track... Maybe someone is better with a two-character matching solution?

------------------------------------------------------------------------
<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"> 

<xsl:variable name="noYes" select="'NY'" />
<xsl:variable name="weekDays" select="'SMTWHFA'" />

<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, 1)" />
   </xsl:when>
  <xsl:otherwise>_</xsl:otherwise>
 </xsl:choose>  

 <xsl:if test="string-length($YNFlags) &gt; 1" >
  <xsl:call-template name="parseYNFlags">
    <xsl:with-param name="YNFlags" select="substring($YNFlags, 2)" />
    <xsl:with-param name="dayAbbreviations"
select="substring($dayAbbreviations, 2)" />
  </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>
  <xsl:value-of select="$temp" />
</xsl:template>
</xsl:stylesheet>



-----Original Message-----
From: Scott Downie [mailto:sdownie@xxxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, February 28, 2001 2:31 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Parsing a character string


I'm flailing about in my attempt to parse a simple string, identify its
elements, and map those elements to a set of output strings. 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.