Solved

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

Posted on 2006-10-28
5
756 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:rkckjk
  • 3
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 17826367
Maybe this is what you need

    <xsl:template match="Info">
        <table border="1">
            <xsl:choose>
                <xsl:when test="JOBS[. != '']">
                    <tr>
                        <td><h3>Jobs Tabled</h3></td>
                        <td> <xsl:text>Total # of Job Failures: </xsl:text><xsl:value-of select="numJOBS"/></td>
                    </tr>
                    <tr><td><pre><xsl:value-of select="JOBS"/></pre></td><td></td></tr>
                </xsl:when>
                <xsl:otherwise>
                    <tr><td> <xsl:text>Total # of Job Failures: </xsl:text><xsl:value-of select="numJOBS"/></td></tr>
                </xsl:otherwise>
            </xsl:choose>
        </table>
    </xsl:template>

Throw away the JOBS templates and organise everything from inside the Info template

I put everything in a table to have a visual effect
but of course you should not have a <h3> in a table cell

cheers

Geert
0
 
LVL 2

Author Comment

by:rkckjk
ID: 17826517
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>


0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17826577
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
0
 
LVL 2

Author Comment

by:rkckjk
ID: 17826627
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>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17826645
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?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which free XML software can I use for opening and editing an XML file? 15 111
XML file fails to process correctly 3 58
Unattended XML settings 4 111
AL3 Files 4 28
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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