Solved

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

Posted on 2006-10-28
5
738 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Header in SQL XML PATH 4 46
SQL Remove Elements from XML 6 39
RSS Feed Parsing for Images 5 45
Custom Ribbon doesn't refresh 7 59
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now