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

RE: Q - Parsing & Manipulating Strings from XSL

Subject: RE: Q - Parsing & Manipulating Strings from XSL
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 29 May 2005 15:19:05 +0100
xsl replace colon in string
>  A soap response contains a complex hierarchy of data, in which, if
> the departure time is 00:45 hours then it is represented as 45 ! To
> make matters worse, the schema defines it as a string. I have no
> influence over the schema since I'm querying a webservice. So I need
> to pad that 45 with 0s and of course add that colon. Is there a way I
> can do that in XSL ?

Of course, but first one needs to know how other times are represented. Is
01:30 represented as "01:30", as "0130", as "90", or in some other way? And
is 00:05 represented as "5" or as "05"?
>  
>  Furthermore, in the same repsonse, I have a string of the format
> YYYYNYY [chars may be either Y or N], also respresented as a free
> format string. This represents the days of the week starting from
> Sunday...  Now I need to take each char, and replace it with a <TD
> color="green">S</TD> if it is Y, and <TD>S</TD> if it is N.
>  
>  Anyway I can do that in XSL ?
>  

Sure. In XSLT 2.0 do

<xsl:for-each select="1 to 7">
  <TD>
    <xsl:if test="substring($in, ., 1) = 'Y'">
      <xsl:attribute name="color">green</xsl:attribute>
    </xsl:if>
    <xsl:text>S</xsl:text>
  </TD>
</xsl:if>

In 1.0 the simplest solution is probably simply to unfold the loop, i.e.
repeat the content of the above for-each loop seven times changing the
second argument of substring() each time.

Michael Kay
http://www.saxonica.com/

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.