Richard Kreidl
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:#0 0c;font-si ze:medium; margin-bot tom:0px;ma rgin-top:1 ex}
pre {word-wrap:break-word;font -family: arial, san-serif;margin-top:0px;f ont-size:1 5px;font-w eight: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
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:#0
pre {word-wrap:break-word;font
</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
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
My partial XML file:
<?xml version="1.0" standalone="yes"?>
<MSR>
<Info>
<JOBS>CN00039(IM10286877)<
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 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
ASKER
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>stormgmtudbOnline Cmrmgr2pBk p
stormgmtudbOnlineCmlibr2pB kp
</AutoSys>
<ES00014>12:20am</ES00014>
<LASTSRDY>11:52pm</LASTSRD Y>
<SSEC>1:17am</SSEC>
<SIVU>2:55am</SSEC>
<JOBS>CN00039(IM10286877)< /JOBS>
<numJOBS>5</numJOBS>
</Info>
</MSR>
<?xml version="1.0" standalone="yes"?>
<MSR>
<Info>
<AutoSys>stormgmtudbOnline
stormgmtudbOnlineCmlibr2pB
</AutoSys>
<ES00014>12:20am</ES00014>
<LASTSRDY>11:52pm</LASTSRD
<SSEC>1:17am</SSEC>
<SIVU>2:55am</SSEC>
<JOBS>CN00039(IM10286877)<
<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?
you can still use the pull technique instead of your apply-templates
what do you see that is not working?
ASKER
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
stormgmtudbOnlineCmrmgr2pB
stormgmtudbOnlineCmlibr2pB
Here's a bigger slice of the XML file:
<?xml version="1.0" standalone="yes"?>
<MSR>
<Info>
<AutoSys>stormgmtudbOnline
stormgmtudbOnlineCmlibr2pB
</AutoSys>
<ES00014>12:20am</ES00014>
<LASTSRDY>11:52pm</LASTSRD
<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:template match="/">
<html>
<head>
<style type="text/css">
body {background-color:#f5f5f5}
h3 {font-weight:bold;color:#0
pre {word-wrap:break-word;font
</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-leng
<h3>Sales</h3>
<xsl:apply-templates select="LASTSRDY"/>
</xsl:if>
<xsl:if test="SSEC[string-length(.
<h3>Securities</h3>
<xsl:apply-templates select="SSEC"/>
<xsl:apply-templates select="SIVU"/>
</xsl:if>
<xsl:if test="ES00014[string-lengt
<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(subs
<xsl:variable name="AMTime"
select="(contains(translat
or (contains(translate(text()
<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(.) >0)))">#FF0000</xsl:whe
<xsl:when test="not($AMTime)">#00CC0
<xsl:otherwise>#FF6633</xs
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="." />
<xsl:if test="$AMTime"><xsl:text>;
</font></li>
</xsl:template>
<xsl:template match="SIVU[. != '']">
<xsl:variable name="time" select="number(concat(subs
<xsl:variable name="AMTime"
select="(contains(translat
or (contains(translate(text()
<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(.) >0)))">#FF0000
</xsl:when>
<xsl:when test="not($AMTime)">#00CC0
<xsl:otherwise>#FF6633</xs
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="." />
<xsl:if test="$AMTime"><xsl:text>;
</font></li>
</xsl:template>
<xsl:template match="ES00014[. != '']">
<xsl:variable name="time" select="number(concat(subs
<xsl:variable name="AMTime"
select="(contains(translat
<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(.) >0)))">#FF0000
</xsl:when>
<xsl:when test="not($AMTime)">#00CC0
<xsl:otherwise>#FF6633</xs
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="." />
<xsl:if test="$AMTime"><xsl:text>;
</font></li>
</xsl:template>
<xsl:template match="LASTSRDY[. != '']">
<xsl:variable name="time" select="number(concat(subs
<xsl:variable name="AMTime"
select="(contains(translat
or (contains(translate(text()
<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(.) >0)))">#FF0000
</xsl:when>
<xsl:when test="not($AMTime)">#00CC0
<xsl:otherwise>#FF6633</xs
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="." />
<xsl:if test="$AMTime"><xsl:text>;
</font></li>
</xsl:template>
<xsl:template name="color">
<xsl:param name="int" select="number(7)" />
<xsl:variable name="hours" select="number(substring-b
<xsl:variable name="minutes" select="number(substring(s
<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(transl
<xsl:when test="($AM or $AM1) and ($hours = 12) and ($minutes >= 0)">#00CC00
</xsl:when>
<xsl:when test="((($AM or $AM1) and ($hours >= $int) and ($minutes > 0)) or (($AM or $AM1) and ($hours > $int) and ($minutes = 0)))">#FF6633</xsl:when>
<xsl:otherwise>#00CC00</xs
</xsl:choose>
</xsl:template>
<xsl:template match="JOBS[. != '']">
<h3>Jobs Tabled</h3><pre><xsl:value
</xsl:template>
<xsl:template match="AutoSys[. != '']">
<h3>AutoSys Jobs Tabled</h3><pre><xsl:value
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>