Link to home
Start Free TrialLog in
Avatar of Richard Kreidl
Richard KreidlFlag for United States of America

asked on

Need to combine two <xsl:value-of select="."/> if possible into one <xsl:template match>

I'm currently using VB .Net to transform my XML and XSL into a HTML file.

I have two elements in the XML file called JOBS and numJOBS that I need to interrupt.

My partial XSL file:

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

<xsl:output method="html" indent="yes" />
<xsl:template match="/">

<html>
<head>

<style type="text/css">
body {background-color:#f5f5f5}
h3 {font-weight:bold;color:#00c;font-size:medium;margin-bottom:0px;margin-top:1ex}
pre {word-wrap:break-word;font-family: arial, san-serif;margin-top:0px;font-size:15px;font-weight:bold}
</style>

</head>
<body>

<xsl:apply-templates select="MSR/Info"/>
</body>
</html>

</xsl:template>

<xsl:template match="Info">
<xsl:apply-templates select="JOBS"/>
<xsl:apply-templates select="numJOBS"/>
</xsl:template>

<xsl:template match="JOBS[. != '']">
<h3>Jobs Tabled</h3><pre><xsl:value-of select="."/></pre>
</xsl:template>

<xsl:template match="*"/>
</xsl:stylesheet>

My partial XML file:

<?xml version="1.0" standalone="yes"?>
<MSR>
  <Info>
     <JOBS>CN00039(IM10286877)</JOBS>
    <numJOBS>5</numJOBS>
     </Info>
</MSR>


So, basically if there's data in both elements: numJOBS and JOBS in which case there is, I would want the output on the HTML page to look like this:

Jobs Tabled               Total # of Job Failures: 5
CN00039


If there's data in only the 'numJOBS' element, it would look like this:

Total # of Job Failures: 5

If there's no data in either element then nothing would appear.


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard Kreidl

ASKER

That's not going to work based on how the XML file is layed out. I just gave you a small sample of the XML and XSL file.

Sales
Daily Sales Reporting Cycle ended (1am SLA) at: 11:52pm

Securities
Securities System Extract Cycle ended (2:30am SLA) at: 1:17am
Securities Investment Warehouse Update ended (6am SLA) at: 2:55am

Commissions
Daily Commissions ended (7am SLA) at: 12:20am

Jobs Tabled
MQ00002(IM10234988)

AutoSys Jobs Tabled
stormgmtudbOnlineCmrmgr2pBkp
stormgmtudbOnlineCmlibr2pBkp

Here's a bigger slice of the XML file:
<?xml version="1.0" standalone="yes"?>
<MSR>
  <Info>
    <AutoSys>stormgmtudbOnlineCmrmgr2pBkp
stormgmtudbOnlineCmlibr2pBkp
</AutoSys>
     <ES00014>12:20am</ES00014>
    <LASTSRDY>11:52pm</LASTSRDY>
     <SSEC>1:17am</SSEC>
    <SIVU>2:55am</SSEC>
    </Info>
</MSR>

Here's a bigger slice of the XSl file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="html" indent="yes" />

<xsl:param name="digits">0123456789</xsl:param>

<xsl:template match="/">

<html>
<head>

<style type="text/css">
body {background-color:#f5f5f5}
h3 {font-weight:bold;color:#00c;font-size:medium;margin-bottom:0px;margin-top:1ex;text-decoration:underline}
pre {word-wrap:break-word;font-family: arial, san-serif;margin-top:0px;font-size:15px;font-weight:bold}
</style>

</head>
<body>

<H1>Operations Status Report</H1>

  <xsl:apply-templates select="MSR/Info"/>

<xsl:call-template name="foot" />

</body>
</html>

</xsl:template>

<xsl:template match="Info">

<xsl:if test="LASTSRDY[string-length(.) != 0]">
<h3>Sales</h3>
<xsl:apply-templates select="LASTSRDY"/>
</xsl:if>

<xsl:if test="SSEC[string-length(.) != 0] or SIVU[string-length(.) != 0]">
<h3>Securities</h3>
<xsl:apply-templates select="SSEC"/>
<xsl:apply-templates select="SIVU"/>
</xsl:if>

<xsl:if test="ES00014[string-length(.) != 0]">
<h3>Commissions</h3>
<xsl:apply-templates select="ES00014"/>
</xsl:if>

<xsl:apply-templates select="JOBS"/>
<xsl:apply-templates select="AutoSys"/>

</xsl:template>

      
      <xsl:template match="SSEC[. != '']">
          <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('2.3') and $time &lt; number('12')))
            or (contains(translate(text(), 'pm', 'PM'), 'PM') and ($time = number('12')))"/>
                   <li>Securities System Extract <font color="#6666ff">(2:30am SLA)</font> ended at: <font>
            <xsl:attribute name="color">
            <xsl:choose>
                  <xsl:when test="((.='Not completed; See comment below') or (string($chkSSEC)='run' and (string-length(.) &gt;0)))">#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"><xsl:text>; See comment below</xsl:text></xsl:if>
        </font></li>
    </xsl:template>

      <xsl:template match="SIVU[. != '']">
          <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('6.0') and $time &lt; number('12')))
            or (contains(translate(text(), 'pm', 'PM'), 'PM') and ($time = number('12')))"/>
                   <li>Securities Investment Warehouse Update <font color="#6666ff">(6am SLA)</font> ended at: <font>
            <xsl:attribute name="color">
            <xsl:choose>
                  <xsl:when test="((.='Not completed; See comment below') or (string($chkSIVU)='run' and (string-length(.) &gt;0)))">#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"><xsl:text>; See comment below</xsl:text></xsl:if>
        </font></li>
    </xsl:template>

      
      
      <xsl:template match="ES00014[. != '']">
          <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(), 'pm', 'PM'), 'PM') and ($time &gt; number('12') or $time &lt; number('12')))"/>
             <li>Semi-Monthly Commissions <font color="#6666ff">(12pm SLA)</font> ended at: <font>
            <xsl:attribute name="color">
            <xsl:choose>
                  <xsl:when test="((.='Not completed; See comment below') or (string($chkES14)='run' and (string-length(.) &gt;0)))">#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"><xsl:text>; See comment below</xsl:text></xsl:if>
        </font></li>
    </xsl:template>

      
      <xsl:template match="LASTSRDY[. != '']">
          <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('1.0') and $time &lt; number('12')))
            or (contains(translate(text(), 'pm', 'PM'), 'PM') and ($time = number('12')))"/>
                   <li>Daily Sales Reporting <font color="#6666ff">(1am SLA)</font> ended at: <font>
            <xsl:attribute name="color">
            <xsl:choose>
                  <xsl:when test="((.='Not completed; See comment below') or (string($chkSRDY)='run' and (string-length(.) &gt;0)))">#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"><xsl:text>; See comment below</xsl:text></xsl:if>
        </font></li>
    </xsl:template>

      
<xsl:template name="color">
<xsl:param name="int" select="number(7)" />
<xsl:variable name="hours" select="number(substring-before(.,':'))"/>
<xsl:variable name="minutes" select="number(substring(substring-after(.,':'),1,2))"/>
<xsl:variable name="AM" select="contains(.,'AM')"/>
<xsl:variable name="AM1" select="contains(.,'am')"/>
<xsl:choose>
<xsl:when test="string(number(.)) != 'NaN'"> </xsl:when>
<!-- will test for "semi" - numeric values -->
<xsl:when test="string-length(translate(.,$digits,'')) = string-length(.)">#FF0000</xsl:when>
<xsl:when test="($AM or $AM1) and ($hours = 12) and ($minutes &gt;= 0)">#00CC00
</xsl:when>
<xsl:when test="((($AM or $AM1) and ($hours &gt;= $int) and ($minutes &gt; 0)) or (($AM or $AM1) and ($hours &gt; $int) and ($minutes = 0)))">#FF6633</xsl:when>
<xsl:otherwise>#00CC00</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="JOBS[. != '']">
<h3>Jobs Tabled</h3><pre><xsl:value-of select="."/></pre>
</xsl:template>

<xsl:template match="AutoSys[. != '']">
<h3>AutoSys Jobs Tabled</h3><pre><xsl:value-of select="."/></pre>
</xsl:template>

<xsl:template match="*"/>

</xsl:stylesheet>


I don't see why that approach would not work in your new XSLT
(I can't make a judgement on the XML because the JOBS have dissapeared from your XML)

in your Info template
I see this
<xsl:apply-templates select="JOBS"/>

There you push the JOBS node(s) to the templates
I suggest that you pull the JOBS node in, instead
which hardly makes a difference

The JOBS and numJOBS logic I showed in my previous comment
just needs to replace the <xsl:apply-templates select="JOBS"/>

I am sorry, but I don't see why it would not work

cheers

Geert
I'm sorry I messed up on my copy and paste. The JOBS and numJOBS are back in the XML.

<?xml version="1.0" standalone="yes"?>
<MSR>
  <Info>
    <AutoSys>stormgmtudbOnlineCmrmgr2pBkp
stormgmtudbOnlineCmlibr2pBkp
</AutoSys>
     <ES00014>12:20am</ES00014>
    <LASTSRDY>11:52pm</LASTSRDY>
     <SSEC>1:17am</SSEC>
    <SIVU>2:55am</SSEC>
<JOBS>CN00039(IM10286877)</JOBS>
    <numJOBS>5</numJOBS>
    </Info>
</MSR>
I see, but still it makes no difference,
you can still use the pull technique instead of your apply-templates
what do you see that is not working?