xsl-list
[Top] [All Lists]

RE: Q - Parsing & Manipulating Strings from XSL

2005-05-29 08:29:42

One more thing... about this code :

<xsl:if test="substring(DaysOperates, ., 1) = 'Y'">
 <xsl:attribute name="class">colorHighlighting</xsl:attribute>
 </xsl:if>
<xsl:text>M</xsl:text>

This (and 6 other instances of this code) is placed inside a
<xsl:for-each select="AvailFlt"></xsl:for-each> statement. This
AvailFlt tag contains the DayOperates tag...

In my 2.0 code I was iterating over (1 to 7), so "." was "1" the first time,
"2" the second, and so on. If you unfold the loop you must replace "." by
the numbers 1 to 7 in turn.

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


But the test expression never evaluates to true.. where am I 
going wrong..

Look forward to your reply,

Thanks & Best Regards,

Ahsan

On 5/29/05, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
This way might seem a little strange, but should work:

At the top-level of your stylesheet specify:

   <xsl:decimal-format name="time" grouping-separator=":"/>

then where you want to do the conversion write:

   <xsl:value-of select="format-number(., '00:00', 'time')"/>

Not tested.

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



-----Original Message-----
From: Ahsan Ali [mailto:doubleletter(_at_)gmail(_dot_)com]
Sent: 29 May 2005 15:35
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Q - Parsing & Manipulating Strings from XSL

Dear Michael,

Thanks for your quick & helpful reply. To answer your question:

If the time is 12:45 it is returned as 1245.
If it is 01:50 it is returned as 150
If it is 00:45 it is returned 45
if it is 00:04 it is returned as 4 !

So that's why I want to pad the beginning of string with 
0s until its
length is 4.

Its a strange way to do it, but as I said, I have to make the
best of it.

Also, I'm sorry to say I'm not very familiar with 
XQuery... what does
$in have to be replaced with ? I'm getting an error.. 
FYI, the data is
given as <JrnyTm>150</JrnyTm>

Best Regards,

Ahsan

On 5/29/05, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
 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/





--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--






--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--





--~------------------------------------------------------------------
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>
--~--