Matlab, Matrix-Division. Showing multile results / non trivial result - matlab

I have a 5x5 Matrix A:
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
</style>
<table class="tg">
<tr>
<th class="tg-031e">-4</th>
<th class="tg-031e">0</th>
<th class="tg-031e">0</th>
<th class="tg-031e">1</th>
<th class="tg-031e">0</th>
</tr>
<tr>
<td class="tg-031e">1</td>
<td class="tg-031e">-5</td>
<td class="tg-031e">0</td>
<td class="tg-031e">0</td>
<td class="tg-031e">4</td>
</tr>
<tr>
<td class="tg-031e">-6</td>
<td class="tg-031e">-6</td>
<td class="tg-031e">-6</td>
<td class="tg-031e">0</td>
<td class="tg-031e">0</td>
</tr>
<tr>
<td class="tg-031e">1</td>
<td class="tg-031e">0</td>
<td class="tg-031e">1</td>
<td class="tg-031e">0</td>
<td class="tg-031e">0</td>
</tr>
<tr>
<td class="tg-031e">0</td>
<td class="tg-031e">2</td>
<td class="tg-031e">0</td>
<td class="tg-031e">0</td>
<td class="tg-031e">0</td>
</tr>
</table>
and want to find a vector x:
A*x = 0.
The only way I can think of is by left division in matlab. This gives a trivial result for x: x = [0 0 0 0 0].
Anyhow, in this case i want the result:
x = [1 0 -1 4 -0.25]
does someone know how I can get this?

You're probably looking for the null function. But it doesn't give the exact answer without some transformations:
x = -null(A,'r')/4
Seems to work.

Related

How can get html inner tag in PosgreSQL

I have some data like that. And I want to get html.
with t(x) as (values( XMLPARSE(DOCUMENT ('<root><NotificationServiceDetails NotificationNo="0" AlarmCode="mail" AlarmStartTime="10:00:00" AlarmTime="0" Id ="2" ><NotificationServiceDetail Id="2"><Title><![CDATA[aaaaaaaaaaaaa]]></Title><ContentJson><![CDATA[
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body>
<table style="font-family: 굴림,맑은 고딕; font-size:12px;color:#333333;border-width: 1px;border-color: #ddd; border-collapse: collapse; margin:5px;width:auto; min-width:600px;">
<tbody>
<tr>
<td colspan="2" style="border-width: 1px;padding: 10px;border-style: solid;border-color: #ddd; background-color: #f5f5f5; text-align:left; font-weight:bold; font-size:13px;">aaaaaaaaaaaaa</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Writer</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Nguyen Ngo Giap (General Mgr.)</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Date</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">2022-01-04 10:00~11:00</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Schedule Div.</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">테스트함</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Content</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">aaaaaaaaaa</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Share</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;"></td>
</tr>
</tbody>
</table>
</body>
</html>
]]></ContentJson></NotificationServiceDetail></NotificationServiceDetails></root>'))))
select
unnest((xpath('//NotificationServiceDetails/NotificationServiceDetail/#Id',t.x)))::text::integer as Id,
unnest((xpath('//NotificationServiceDetails/NotificationServiceDetail/Title/text()',t.x))):: text::character varying as Title,
unnest(xpath('//NotificationServiceDetails/NotificationServiceDetail/ContentJson/text()',t.x))::xml as ContentJson,
t.x
from t;
but the ContentJson column gives me special characters. "<..." I want the real html
Expect result for column ContentJson.
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body>
<table style="font-family: 굴림,맑은 고딕; font-size:12px;color:#333333;border-width: 1px;border-color: #ddd; border-collapse: collapse; margin:5px;width:auto; min-width:600px;">
<tbody>
<tr>
<td colspan="2" style="border-width: 1px;padding: 10px;border-style: solid;border-color: #ddd; background-color: #f5f5f5; text-align:left; font-weight:bold; font-size:13px;">aaaaaaaaaaaaa</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Writer</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Nguyen Ngo Giap (General Mgr.)</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Date</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">2022-01-04 10:00~11:00</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Schedule Div.</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">테스트함</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Content</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">aaaaaaaaaa</td>
</tr>
<tr>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;">Share</td>
<td style="padding: 15px; background-color: #f9f9f9; text-align:left;"></td>
</tr>
</tbody>
</table>
</body>
</html>
How can I do that
So far, I've provided 5 different solutions - all with their own advantages and problems - you'll have to test on your own data and hardware to ensure that it's working for you!
I did the following (all the relevant code is available on the fiddle here):
CREATE TABLE t (x TEXT);
and populated it with some text similar to yours, but shorter to making testing easier:
INSERT INTO t VALUES
($SOMETAG$with t(x) as (values( XMLPARSE(DOCUMENT ('<root><NotificationServiceDetails NotificationNo="0" AlarmCode="mail" AlarmStartTime="10:00:00" AlarmTime="0" Id ="2" ><NotificationServiceDetail Id="2"><Title><![CDATA[aaaaaaaaaaaaa]]></Title><ContentJson><![CDATA[
<html lang="en">
<head>
<meta charset="utf-8"/>
more stuff
more stuff
</table>
</body>
</html>
]]></ContentJson></NotificationServiceDetail></NotificationServiceDetails></root>'))))
select
unnest((xpath('//NotificationServiceDetails/NotificationServiceDetail/#Id',t.x)))::text::integer as Id,
unnest((xpath('//NotificationServiceDetails/NotificationServiceDetail/Title/text()',t.x))):: text::character varying as Title,
unnest(xpath('//NotificationServiceDetails/NotificationServiceDetail/ContentJson/text()',t.x))::xml as ContentJson,
t.x
from t;$SOMETAG$);
I picked up the $SOMETAG$...$SOMETAG$ technique here - very helpful for insterting characters like single quote (') and backslash (\).
There is a "one-pass" solution possible - it justs takes time patience to work it out. Oh, and BTW, there were slight errors in my orininal solution - since corrected.
Part 1:
First I remove all characters up to but not including <html lang="en"> as follows:
SELECT SUBSTRING(x, STRPOS (x,'<html lang="en"'));
SUBSTRING and STRPOS were taken from this snippet.
Part 2:
Then, I reverse that string using the REVERSE() function
Part 3:
Finally, I use the SUBSTRING/STRPOS "trick" to chop of the other end of the string to the point of <ydob>
Part 4 is the pièce de résistance
I reREVERSE() the string to bring it back to its original state - minus the undesirable bits to give the required result.
1st Solution (pretty horrible):
SELECT REVERSE(SUBSTR( REVERSE(SUBSTR(x, strpos(x, '<html lang="en">'))), strpos( REVERSE(SUBSTR(x, strpos(x, '<html lang="en">'))), '>lmth/<'))) FROM t;
It looks a bit better (or is more legible at lease):
SELECT
REVERSE(
SUBSTR(
REVERSE(
SUBSTR(x, strpos(x, '<html lang="en">'))),
strpos(
REVERSE(
SUBSTR(x, strpos(x, '<html lang="en">'))), '>lmth/<'))) FROM t;
Instead of these horrible constructions, I used CTE's (Common Table Expressions - AKA the WITH CLAUSE to do this as follows:
Code spends most of its life in maintenance, so easier to read code is easier to repair.
WITH cte1 AS
(
SELECT REVERSE(SUBSTR(x, strpos(x, '<html lang="en">'))) AS s1 FROM t
), cte2 AS
(
SELECT REVERSE(SUBSTR(s1, strpos(s1, 'ydob'))) AS s2 FROM cte1
)
SELECT * from cte2;
Result:
reverse
<html lang="en">
<head>
<meta charset="utf-8"/>
more stuff
more stuff
</table>
</body>
</html>
The answer is the same for all of them!
2nd Solution (a bit more elegant - fiddle available here):
SELECT SPLIT_PART(x, '</html>', 1) from t;
Result:
split_part
with t(x) as (values( XMLPARSE(DOCUMENT ('<root><NotificationServiceDetails NotificationNo="0" AlarmCode="mail" AlarmStartTime="10:00:00" AlarmTime="0" Id ="2" ><NotificationServiceDetail Id="2"><Title><![CDATA[aaaaaaaaaaaaa]]></Title><ContentJson><![CDATA[
<html lang="en">
<head>
<meta charset="utf-8"/>
more stuff
more stuff
</table>
</body>
<<=== Note there are 7 spaces here
So, SPLIT_PART() cuts the string up to, but not including the delimiter - </html> in this case. So, using this as follows:
So, we combine two SPLIT_PARTs in a CTE as follows:
WITH cte AS
(
SELECT LENGTH(split_part(x, '', 1)) AS beg,
LENGTH(split_part(x, '', 1)) AS fin
FROM t
)
Result:
substring
<html lang="en">
<head>
<meta charset="utf-8"/>
more stuff
more stuff
</table>
</body>
</html>
-- I cannot understand why I have to add 8 characters to the 408 of the length?
--
-- 7 (the length of </html>) I could possibly get, but why 8?
Which is the desired result.
3nd Solution (also reasonably elegant - fiddle available here):
I didn't go through all of the steps this time - I combined them all in one query. The interested reader is invited to go through it line by line.
SELECT
strpos(x, '<html lang="en">'),
strpos(x, '</html>'),
strpos(x, '</html>') - strpos(x, '<html lang="en">'),
substring(x FROM strpos(x, '<html lang="en">')
for ((strpos(x, '</html>') + 8) - strpos(x, '<html lang="en">')) )
FROM t;
--
-- Again, I'm puzzled by the necessity to use 8 characters.
--
--
Result:
strpos strpos ?column? substring
265 409 144 <html lang="en">
<head>
<meta charset="utf-8"/>
more stuff
more stuff
</table>
</body>
</html>
Et voilà - the desired result!
4th Solution (a bit convoluted, but may be instructive - fiddle available here):
1st Step:
I split the lines into records in a table as follows:
SELECT
x.idx,
LENGTH(x.string),
x.string
FROM t,
REGEXP_SPLIT_TO_TABLE(t.x, '\n') WITH ORDINALITY AS x(string, idx);
2nd step:
I pull out the records I want which correspond to the desired result as follows:
WITH cte1 AS
(
SELECT
x.idx,
LENGTH(x.string) AS ls,
x.string
FROM t,
REGEXP_SPLIT_TO_TABLE(t.x, '\n') WITH ORDINALITY AS x(string, idx)
), cte2 AS
(
SELECT idx, ls, string
FROM cte1
WHERE string ~ '<html lang="en">' OR string ~ '</html>'
ORDER BY idx
)
SELECT idx, ls, string
FROM cte1
WHERE idx BETWEEN
(SELECT MIN(idx) FROM cte2) AND (SELECT MAX(idx) FROM cte2);
Result:
idx ls string
2 22 <html lang="en">
3 12 <head>
4 33 <meta charset="utf-8"/>
5 20 more stuff
6 20 more stuff
7 16 </table>
8 13 </body>
9 14 </html>
As you can see, the string field contains the data we want!
Solution 5 - using a relatively simple regular expression - fiddle here
1st pass:
We check the output of the very handy PG_TYPEOF() function, which from the docco here does:
pg_typeof returns the OID of the data type of the value that is passed
to it. This can be helpful for troubleshooting or dynamically
constructing SQL queries. The function is declared as returning
regtype, which is an OID alias type (see Section 8.18); this means
that it is the same as an OID for comparison purposes but displays as
a type name.
So, our first query is:
SELECT
REGEXP_MATCH(x, '^.*(<head>.*</html>).*'),
PG_TYPEOF(REGEXP_MATCH(x, '^.*(<head>.*</html>).*'))
FROM t;
Result:
regexp_match pg_typeof
{"<head>
<meta charset=\"utf-8\"/>
more stuff
more stuff
</table>
</body>
</html>"} text[]
So, we have our data, but it's surrounded by braces (curly brackets) - but we know from our PG_TYPEOF() function is a text array, so we know that it's the first (only) element of that array, so therefore we can use the array element notation as follows:
SELECT
(REGEXP_MATCHES(x, '^.*(<head>.*</html>).*'))[1] -- <<-- Note [1]
FROM t;
Result:
regexp_matches
<head>
<meta charset="utf-8"/>
more stuff
more stuff
</table>
</body>
</html>
Same as the others!
Which is the same as for the others!
Crude performance analysis
After 5 runs, the order of merit appears to be the following (a fiddle of the tests run may be found here. Times will vary according to other uses to which the server may be being put, but as I said, I found them to be fairly consistent in terms of time and always in the same order on the 5 runs that I examined.
In descending order of run time:
1st) Method 3: STRPOS() Time ~ 0.045ms: - let that be a base of 1 times fastest execution
2nd) Method 1 SUBSTRING() & REVERSE() 0.079ms: x times 1.75
3rd) Method 2: SPLIT_PART() x times 2.25
4th) Method 4: REGEXP_SPLIT_TO_TABLE() WITH CTE x times 13.2
5th Method 5: REGEXP_MATCH() x times 49.4
So, we can see that the most expensive algorithm is ~ 50 times more expensive than the most efficient one. The usual caveats about benchmarking with only one record and on an unknown system apply - although the results where fairly consistent over at least 5 runs. Always benchmark on your own system with your own data!

can't set width for auxheader in zk

I have a grid in which I want to set the width for auxheader in .zul but it's not working. I am using zk framework.
<grid id="chartGrid" model="#bind(vm.chartGridModel)" mold="paging"
style="overflow:auto" width="100%" >
<auxhead hflex="2" >
<auxheader hflex="2" align="center" width="200px" label="Date" rowspan="3"/>
</auxhead>
<auxhead hflex="1" children="#bind(vm.legendsFB)" visible="#bind(vm.vFb)" >
<auxheader align="center" width="200px" colspan="1"></auxheader>
<template name="children">
<auxheader align="center" label="#bind(each)" colspan="#bind(
vm.viewType eq '0' ? 3 :2)" hflex="2"/>
</template>
</auxhead>
<columns visible="false"><!-- make it invisible -->
<column width="200px"/><!-- specify width here -->
<column width="150px"/>
<column width="50px"/>
<column width="50px"/>
</columns>
<template name="model">
<row>
<cell align="center" ><label value="#load(each.report_date)"></label>
</cell>
<cell align="center"><label value="#load(each.total_action)"></label>
</cell>
<cell align="center"><label value="#load(each.from_user_male)"></label>
</cell>
<cell align="center"><label value="#load(each.from_user_female)"></label>
</cell>
</row>
</template>
</grid>
You set width and colspan.
colspan="x" means you will take the witdh of x columns of your template.
Now you can remove the colspan and it should work, but remember when you set width in px,
Be sure that the total px are the same as the px of all your rows.
You can also do width = "20%", this would mean that you take 20% of your total size of px of the columns.
Its easier to calculate to 100% then your total px.
Greetz chill.

Importing tables in Mathematica from web - empty cell problem

I use:
data=Import["http://weburl/","Data"]
to import data from one site. On that page there are tables. This creates nested lists, and you can easily get the data in table form. For example:
Grid[data[[1]]]
would give something like this:
Player Age Shots Goals
P1 24 10 2
P2 22 5 0
P3 28 11 1
...
Now, here is the problem. If one cell in the html table is empty, for example an entry for "Age", then in html this would look like this: <td></td>. Mathematica doesn't include take it in the list at all, not even as, for example, a "Null" value. Instead, this row would just be represented by a list of length 3 and data would be moved by one column, so you'd get "Shots" in place of "Age" and "Goals" in place of "Shots" and "Goals" would be empty.
For example, a "P4" whos age is unknown (empty cell in html table), who had 10 shots and scored 0 goals would be imported as list of length 3 not 4 and moved by one:
Player Age Shots Goals
P1 24 10 2
P2 22 5 0
P3 10 0
...
This poses a difficult problem, because if you have a few empty fields then you can't tell from the list to which column it belongs. Is there a way to put a "Null" on an empty cell in html tables when importing in Mathematica? For example, P4 element in list would look like this:
data[[1,5]]
{"P4","Null",10,0}
instead of:
{"P4",10,0}
As lumeng points out, you can use FullData to get the HTML table element to fill out properly. Here's a simpler illustration of this.
in = ImportString["\<<html><table>
<tr>
<td>(1,1)</td>
<td>(1,2)</td>
<td>(1,3)</td>
</tr>
<tr>
<td>(2,1)</td>
<td></td>
<td>(2,3)</td>
</tr>
</table></html>\>",
{"HTML", "FullData"}];
Grid[in[[1, 1]]]
If you want more complete control of the output, I'd suggest that you Import the page as XML. Here's an example.
in = ImportString["\<<html><table>
<tr>
<td>(1,1)</td>
<td>(1,2)</td>
<td>(1,3)</td>
</tr>
<tr>
<td>(2,1)</td>
<td></td>
<td>(2,3)</td>
</tr>
</table></html>\>", "XML"];
Column[Last /# Cases[in,
XMLElement["td", ___], Infinity]]
You'll need to read up a bit on XML in general and Mathematica's version, namely the XMLObject. It's a delight to work with, once you get the hang of it, though.
In[13]:= htmlcode = "<html><table border=\"1\">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td></td>
<td>row 2, cell 3</td>
</tr>
</table><html>";
In[14]:= file = ToFileName[{$TemporaryDirectory}, "tmp.html"]
Out[14]= "/tmp/tmp.html"
In[15]:= OpenWrite[file]
WriteString[file,htmlcode]
Close[file]
FilePrint[file]
Out[15]= OutputStream[/tmp/tmp.html,18]
Out[17]= /tmp/tmp.html
During evaluation of In[15]:=
<html><table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td></td>
<td>row 2, cell 3</td>
</tr>
</table><html>
In[23]:= Import[file,"Elements"]//InputForm
Out[23]//InputForm=
{"Data", "FullData", "Hyperlinks", "ImageLinks", "Images", "Plaintext", "Source", "Title", "XMLObject"}
In[22]:= Import[file,"FullData"]//InputForm
Out[22]//InputForm=
{{{{"row 1, cell 1", "row 1, cell 2", "row 1, cell 3"}, {"row 2, cell 1", "", "row 2, cell 3"}}}, {}}
Using Computist's sample, you could also do:
htmlcode = "<html><table border=\"1\">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td></td>
<td>row 2, cell 3</td>
</tr>
</table><html>";
StringReplace[htmlcode, "<td></td>" -> "<td>###</td>"];
ImportString[%, "Data"] /. "###" -> Null

Sed replace every nth occurrence

I am trying to use sed to replace every other occurrence of an html element of a file so I can make alternating color rows.
Here is what I have tried and it doesn't work.
sed 's/<tr valign=top>/<tr valign=top bgcolor='#E0E0E0'>/2' untitled.html
I'd solve it with awk:
awk '/<tr valign=top>/&&v++%2{sub(/<tr valign=top>/, "<tr valign=top bgcolor='#E0E0E0'>")}{print}' untitled.html
First, it verifies if the line contains <tr valign=top>
/<tr valign=top>/&&v++%2
and whether the <tr valign=top> is an odd found instance:
v++%2
If so, it replaces the <tr valign=top> in the line
{sub(/<tr valign=top>/, "<tr valign=top bgcolor='#E0E0E0'>")}
Since all lines are to be printed, there is a block that always will be executed (for all lines) and will print the current line:
{print}
This works for me:
sed -e "s/<tr/<TR bgcolor='#E0E0E0'/g;n" simpletable.htm
sample input:
<table>
<tr><td>Row1 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row2 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row3 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row4 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row5 / col1</td><td>col2</td><td>col3</td></tr>
</table>
sample output:
<table>
<TR bgcolor='#E0E0E0'><td>Row1 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row2 / col1</td><td>col2</td><td>col3</td></tr>
<TR bgcolor='#E0E0E0'><td>Row3 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row4 / col1</td><td>col2</td><td>col3</td></tr>
<TR bgcolor='#E0E0E0'><td>Row5 / col1</td><td>col2</td><td>col3</td></tr>
</table>
The key is to use the n command in sed, which advances to the next line.
This works only if the TR occupy distinct lines.
It will break with nested tables, or if there are multiple TR's on a single line.
According to http://www.linuxquestions.org/questions/programming-9/replace-2nd-occurrence-of-a-string-in-a-file-sed-or-awk-800171/
Try this.
sed '0,/<tr/! s/<tr/<TR bgcolor='#E0E0E0'/' file.txt
The exclamation mark negates everything from the beginning of the file to the first "Jack", so that the substitution operates on all the following lines. Note that I believe this is a gnu sed operation only.
If you need to operate on only the second occurrence, and ignore any subsequent matches, you can use a nested expression.
sed '0,/<tr/! {0,/<tr/ s/<tr/<TR bgcolor='#E0E0E0'/}' file.txt
Here, the bracketed expression will operate on the output of the first part, but in this case, it will exit after changing the first matching "Jack".
PS, I've found the sed faq to be very helpful in cases like this.
you can use python script to fix the html
from bs4 import BeautifulSoup
html_doc = """
<table>
<tr><td>Row1 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row2 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row3 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row4 / col1</td><td>col2</td><td>col3</td></tr>
<tr><td>Row5 / col1</td><td>col2</td><td>col3</td></tr>
</table>
"""
soup = BeautifulSoup(html_doc, 'html.parser')
index=0
for tr in soup.find_all('tr'):
if tr.find('td'):
if index % 2:
tr.find('td').attrs['style'] = 'background-color: #ff0000;'
else:
tr.find('td').attrs['style'] = 'background-color: #00ff00;'
index+=1
print(soup)

I can't get this page to stop subtracting the xl sales from the total. classic asp

So this page gets all the sales for todays date in a query and then sums them up, but if a sale get's canceled it also subtracts the canceled amount from the total amount, i don't want it to do this and i have tryed many things and still cant get it.
set RScontest = Server.CreateObject("ADODB.Recordset")
RScontest.ActiveConnection = ""
RScontest.Source = SelectData
RScontest.CursorType = 3
RScontest.CursorLocation = 2
RScontest.LockType = 1
RScontest.Open()
if not(rscontest.bof) and not(rscontest.eof) then%><font face="Arial,Helvetica,sans-serif" size=4"><b>
Sales</b>
<table width="100%">
<%
st = ""
pax = 0
sales = 0
PAXTotal = 0
SALESTotal = 0
while not rscontest.eof
if st <> rscontest.fields.item("status") THEN
if st <> "" then
response.write("<tr bgcolor='#F2F2F2'><td >")
%><font face="Arial,Helvetica,sans-serif" size="-1"><%
response.write("Sub Total")%>
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td align='right'>
<font face="Arial,Helvetica,sans-serif" size="-1">
<%response.write(PAX)%>
</td>
<td align='right'>
<font face="Arial,Helvetica,sans-serif" size="-1">
<%response.write(formatnumber(Sales,2))%>
</td>
</tr>
<%PAXTotal = PAXTotal + PAX
SALESTotal = SALESTotal + Sales
PAX = 0
Sales = 0
end if%>
<%response.write("<tr bgcolor='#FADFA0'><td >")
%><font face="Arial,Helvetica,sans-serif" size="-1"><%
response.write(rscontest.fields.item("status") & " Bookings")%>
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
Departure</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
Passenger</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
Source</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
Campaign</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
Tour</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
Agent</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
PAX</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
Amount</td>
</tr>
<%st = rscontest.fields.item("status")
END IF
response.write("<tr><td>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("book7") & " - " & rscontest.fields.item("BTIME"))
response.write("</td><td>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("dep7"))
response.write("</td><td>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("lead"))
response.write("</td><td>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("hear"))
response.write("</td><td>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("cname"))
response.write("</td><td>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("theme") & " - " & rscontest.fields.item("tour"))
response.write("</td><td align='right'>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("userid"))
response.write("</td><td align='right'>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
response.write(rscontest.fields.item("pax_count"))
pax = pax + rscontest.fields.item("pax_count")
response.write("</td><td align='right'>")
%><font face="Arial,Helvetica,sans-serif" size="-2"><%
IF rscontest.fields.item("status") = "XL" then
response.write(formatnumber(rscontest.fields.item("CXVALUE"),2))
sales = sales - formatnumber(rscontest.fields.item("CXVALUE"),2)
ELSE
response.write(formatnumber(rscontest.fields.item("AMOUNT"),2))
sales = sales + formatnumber(rscontest.fields.item("AMOUNT"),2)
END IF
response.write("<tr><td rowspan=1>")
%><font face="Arial,Helvetica,sans-serif" size="-2"></style><%
response.write(rscontest.fields.item("description"))
rscontest.movenext
wend
if st <> "" then
response.write("<tr bgcolor='#F2F2F2'><td >")
%><font face="Arial,Helvetica,sans-serif" size="-1"><%
response.write("Sub Total")%>
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td align='right'>
<font face="Arial,Helvetica,sans-serif" size="-1">
<%response.write(PAX)%>
</td>
<td align='right'>
<font face="Arial,Helvetica,sans-serif" size="-1">
<%response.write(formatnumber(Sales,2))%>
</td>
</tr>
<%
PAXTotal = PAXTotal + PAX
SALESTotal = SALESTotal + Sales
PAX = 0
Sales = 0
response.write("<tr bgcolor='#D3FFA1'><td >")
%><font face="Arial,Helvetica,sans-serif" size="-1"><%
response.write("Total")%>
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td>
<font face="Arial,Helvetica,sans-serif" size="-1">
</td>
<td align='right'>
<font face="Arial,Helvetica,sans-serif" size="-1">
<%response.write(PAXTotal)%>
</td>
<td align='right'>
<font face="Arial,Helvetica,sans-serif" size="-1">
<%response.write(formatnumber(SalesTotal,2))%>
</td>
</tr>
<%end if%>
</table>
<%else%>
No sales for this date...<BR><BR>
<%end if
RScontest.Close()%>
</td>
</tr>
</table>
Improving your Code
Here's a list of things to help you neaten your code up. Without spending much more time on it, I can't see exactly what is wrong (or what you are asking) but following these steps should help you pinpoint the error:
Remove all <font> tags, use CSS
Your record loop would be better by taking values from the recordset into variables first, not calling them repeatedly throughout the loop, IE:
Dim strTitle
Dim intValue1
Dim intTotal
intTotal = 0
while not rscommon.eof
//Take your variables
strTitle = rsCommon("title")
intValue1 = rsCommon("value")
//Process values here, referencing variables not recordset
intTotal = intTotal + intValue1
//Loop your table here
response.write("<tr>")
rsCommon.close
wend
These changes will improve the speed of your loop (significantly) and also make it a lot more structured, helping you pinpoint errors in your logic a lot faster and easier.