?
Solved

Checking value of substring in a XML element

Posted on 2011-10-13
12
Medium Priority
?
305 Views
Last Modified: 2013-11-18
I have the following XML element in my XML file:
<TODAY>Thursday, October 13, 2011</TODAY>

In my snippet of XSL code I would like to check the value of that XML element to see if the text "Friday" is present. I'm not sure how to do that either using "when test" or "if test".

<xsl:template match="LASTISA[. != '']">
        <xsl:variable name="time" select="number(concat(substring-before(normalize-space(text()),':'), '.', substring(substring-after(normalize-space(text()),':'),1,2)))"/>   

<!--If the element contains the text "Friday" do the below-->
		 
      <xsl:variable name="AMTime"  
          select="(contains(translate(text(), 'am', 'AM'), 'AM') and ($time &gt; number('12') or $time &lt; number('12')))
            or (contains(translate(text(), 'pm', 'PM'), 'PM') and ($time = number('12')))"/>
        <li>ISA DataBase <font color="#6666ff">(12am SLA)</font> ended at: <font>

<!--If the element doesn't contains the text "Friday" then do this-->

<xsl:variable name="AMTime"  
        select="(contains(translate(text(), 'am', 'AM'), 'AM') and ($time &gt; number('1.0') and $time &lt; number('12')))
            or (contains(translate(text(), 'pm', 'PM'), 'PM') and ($time = number('12')))"/>       
 <li>ISA DataBase <font color="#6666ff">(1am SLA)</font> ended at: <font>

            <xsl:attribute name="color">
            <xsl:choose>
	<xsl:when test="(.='Not completed; See comment above')">#FF0000</xsl:when>
                <xsl:when test="not($AMTime)">#00CC00</xsl:when>
                <xsl:otherwise>#FF6633</xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
            <xsl:value-of select="." />
            <xsl:if test="$AMTime"><i><xsl:text>; See comment above</xsl:text></i></xsl:if>
        </font></li>
    </xsl:template>

Open in new window


Thanks
0
Comment
Question by:Richard Kreidl
  • 6
  • 6
12 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36967004
<xsl:if test="contains(TODAY, 'Friday')">...
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 36967210
Not working... here's the updated code:
<xsl:template match="LASTISA[. != '']">
        <xsl:variable name="time" select="number(concat(substring-before(normalize-space(text()),':'), '.', substring(substring-after(normalize-space(text()),':'),1,2)))"/> 
        <xsl:variable name="AMTime"  
            select="(contains(translate(text(), 'am', 'AM'), 'AM') and ($time &gt; number('12') or $time &lt; number('12')))
            or (contains(translate(text(), 'pm', 'PM'), 'PM') and ($time = number('12')))"/>
        [b]<li>ISA DataBase <font color="#6666ff">(12am SLA)</font> ended at: <font>[/b]		 <xsl:attribute name="color">
            <xsl:choose>
			<xsl:when test="(.='Not completed; See comment above')">#FF0000</xsl:when>
                <xsl:when test="not($AMTime)">#00CC00</xsl:when>
                <xsl:otherwise>#FF6633</xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
            <xsl:value-of select="." />
            <xsl:if test="$AMTime"><i><xsl:text>; See comment above</xsl:text></i></xsl:if>
        </font></li>
		<xsl:if test="contains(TODAY, 'Friday')">
		 <xsl:variable name="AMTimeF"  
            select="(contains(translate(text(), 'am', 'AM'), 'AM') and ($time &gt; number('1') or $time &lt; number('12')))
            or (contains(translate(text(), 'pm', 'PM'), 'PM') and ($time = number('12')))"/>
        <li>ISA DataBase <font color="#6666ff">(1am SLA)</font> ended at: <font>        
		  <xsl:attribute name="color">
            <xsl:choose>
		<xsl:when test="(.='Not completed; See comment above')">#FF0000</xsl:when>
                <xsl:when test="not($AMTimeF)">#00CC00</xsl:when>
                <xsl:otherwise>#FF6633</xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
            <xsl:value-of select="." />
            <xsl:if test="$AMTimeF"><i><xsl:text>; See comment above</xsl:text></i></xsl:if>
        </font></li>
		</xsl:if>
    </xsl:template>

Open in new window


What am I doing wrong?
I tested the XSL with 'Friday' in the XML element:TODAY and the if statement doesn't seem to be working..
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36967219
Can you send us a sample LASTISA XML?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:Richard Kreidl
ID: 36967222
<?xml version="1.0" standalone="yes"?>
<MSR>
  <Info>
    <AutoSys>None</AutoSys>
    <BT30004>8:04pm</BT30004>
    <CICS />
    <CICST />
    <CM10009 />
    <CMHM />
    <COMP />
    <CSI>CSI outage report will be sent out by the CSI team on Next Business Day.</CSI>
    <Comment />
    <DISTM />
    <DISTS />
    <EBIS />
    <ES00014>2:09am</ES00014>
    <FADS>11:01pm</FADS>
    <FIXA>7:33pm</FIXA>
    <FM24FHR />
    <FMDNFHR />
    <FMI />
    <GDC>9:46pm</GDC>
    <ICCA />
    <ICTM>7:06pm</ICTM>
    <IMZ />
    <IMZT />
    <INSH>8:02pm</INSH>
    <LASTISA>9:15pm</LASTISA>    
<LASTSRM1 />
    <LASTSRM2 />
    <LASTSRM2A />
    <MADYFHR>8:00pm</MADYFHR>
    <MVS>HR80007  IM10919471 also tables ES00024</MVS>
    <NITECOMM />
    <ODSFHR />
    <PAYFHR />
    <PDBN>8:30pm</PDBN>
    <PSF />
    <PSLDFHR />
    <RPI />
    <SALES>5:45am</SALES>
    <SAMS />
    <SIVU />
    <SSEC>11:19pm</SSEC>
    <STMT>CSI outage on Sunday from 12:00am to hh:mm am/pm due to scheduled maintenance.</STMT>
    <TEEFHR />
    <TEPP>7:49pm</TEPP>
    <TNC />
    <TODAY>Friday, October 13, 2011</TODAY>  
  <UMZ />
    <UMZT />
    <UPDATE />
    <maxAutoSys>0</maxAutoSys>
    <numAutoSys>0</numAutoSys>
    <numMVS>0</numMVS>
  </Info>
</MSR>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36967266
OK, TODAY is not part of TODAY, it is a sibling, so you will need

        <xsl:if test="contains(../TODAY, 'Friday')">
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 36967299
Now, when I change the TODAY element to: Friday. I get the following two lines in my HTML:

ISA DataBase (12am SLA) ended at: 9:15pm
ISA DataBase (1am SLA) ended at: 9:15pm

I'm only supposed to get the following line:
ISA DataBase (1am SLA) ended at: 9:15pm

0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 36967303
Maybe I need to use a "choose" instead of "if"
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36967333
well, I couldn't possibly know the logic you need if you don't specify it.

If both are mutually exclusive then you need a choose indeed
0
 
LVL 2

Author Comment

by:Richard Kreidl
ID: 36967359
Basically, the logic is if it's a Friday we want to display this line that has a "1am SLA" and check the time to see if it's before 1am.

ISA DataBase (1am SLA) ended at: 9:15pm

On Mondays through Thursdays we want this line displayed and check to see if the time is before midnight:

ISA DataBase (12am SLA) ended at: 9:15pm


How would I code the choose statement?

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 36967368
<xsl:choose>
<xsl:when test="contains(../TODAY, 'Friday')">
do the friday stuff
</xsl:when>
<xsl:otherwise>
do the rest of week stuff
</xsl:otherwise>
</xsl:choose>
0
 
LVL 2

Author Closing Comment

by:Richard Kreidl
ID: 36967398
Thanks!!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36967480
welcome
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question