Hi Michael ,
Thanks for your reply.
$sortCol = the index of the column to sort by. I pass it to the xslt.
$msrs = number of measures I get by counting number of Measures. This can change.
<xsl:variable name="msrs">
<xsl:choose>
<xsl:when test="//Measure">
<xsl:value-of select="count(//Measure)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
"
You don't make it clear which part of the source XML you are sorting. Cells within a Row, perhaps?
"
I am trying to sort the @val attribute within Cells within a Row. Please see the comlete xml below.
"
In that case, why are you using descendant::Msr rather than child::Msr?
"
I am using descendant because it worked when I tried the expression below in FireFox and I thought this was the right expression.
//Report/Rows//Row/descendant::Msr[12]/@val
This returns the @Val sorted and I get 20 matches.
However when I change the index to 2 :
//Report/Rows//Row/descendant::Msr[2]/@val
I get 32 matches instead and I think this is happening because of the empty Cells. The empty Cell nodes are messing up the sorting.
"
//Row/Cell[not(Msr)][ceiling($sortCol div $msrs)]
Why the "//Row"? You need an expression that selects relative to the elements being sorted. The first predicate here selects Cell elements that have no Msr children."
you are right. I was trying to retun something from the empty Cells rather than a node.
The )][ceiling($sortCol div $msrs)] expression I was using to get This:
Suppose that the $sortCol = 7 and $msrs = 2
//Row/Cell[not(Msr)][ceiling(7 div 2)])
So:
when count(//Measures) = 2
sortCol = 5 -> Cell[3]
sortCol = 7 -> Cell[4]
sortCol = 6 -> Cell[3]
Then:
when count(//Measures) = 3
sortCol = 5 -> Cell[2]
sortCol = 7 -> Cell[3]
sortCol = 6 -> Cell[2]
Basically, what I need to do is to sort the xml based on the @val attribute value within Cells within a Row. However, The empty Cells (which have no Mrs elements) are messing up the sorting)!!
Cheers
CP
XML
<Report xmlns="">
<Measures>
<Measure idx="1" heading="Cost" />
<Measure idx="2" heading="Total Pages" />
</Measures>
<Columns>
<ColGrp heading="Quarter">
<ColGrp heading="2003">
<Col heading="Quarter 1" />
<Col heading="Quarter 2" />
<Col heading="Quarter 3" />
<Col heading="Quarter 4" />
</ColGrp>
<ColGrp heading="2004">
<Col heading="Quarter 1" />
<Col heading="Quarter 2" />
<Col heading="Quarter 3" />
<Col heading="Quarter 4" />
</ColGrp>
</ColGrp>
</Columns>
<Rows>
<RowGrp heading="Product Name">
<RowGrp heading="Abbott Labs">
<RowGrp heading="Ross Labs">
<Row heading="Collagenase Santyl">
<Cell />
<Cell />
<Cell />
<Cell />
<Cell>
<Msr idx="1" val="$21,270.00" />
<Msr idx="2" val="6.00" />
</Cell>
<Cell>
<Msr idx="1" val="$33,306.00" />
<Msr idx="2" val="9.50" />
</Cell>
<Cell>
<Msr idx="1" val="$25,206.00" />
<Msr idx="2" val="6.50" />
</Cell>
<Cell>
<Msr idx="1" val="$14,511.00" />
<Msr idx="2" val="4.70" />
</Cell>
</Row>
<Row heading="Oxandrin">
<Cell>
<Msr idx="1" val="$67,636.00" />
<Msr idx="2" val="18.00" />
</Cell>
<Cell>
<Msr idx="1" val="$212,080.00" />
<Msr idx="2" val="62.00" />
</Cell>
<Cell>
<Msr idx="1" val="$235,448.00" />
<Msr idx="2" val="66.00" />
</Cell>
<Cell>
<Msr idx="1" val="$189,981.00" />
<Msr idx="2" val="50.00" />
</Cell>
<Cell>
<Msr idx="1" val="$117,320.00" />
<Msr idx="2" val="36.00" />
</Cell>
<Cell>
<Msr idx="1" val="$188,855.00" />
<Msr idx="2" val="54.00" />
</Cell>
<Cell>
<Msr idx="1" val="$24,390.00" />
<Msr idx="2" val="6.00" />
</Cell>
<Cell>
<Msr idx="1" val="$34,120.00" />
<Msr idx="2" val="8.00" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Boehringer Ingelheim Pharma">
<RowGrp heading="Boehringer Ingelheim Pharma">
<Row heading="Aggrenox">
<Cell>
<Msr idx="1" val="$119,109.00" />
<Msr idx="2" val="73.00" />
</Cell>
<Cell>
<Msr idx="1" val="$66,155.00" />
<Msr idx="2" val="43.00" />
</Cell>
<Cell>
<Msr idx="1" val="$69,284.00" />
<Msr idx="2" val="45.00" />
</Cell>
<Cell>
<Msr idx="1" val="$175,181.00" />
<Msr idx="2" val="63.00" />
</Cell>
<Cell>
<Msr idx="1" val="$154,571.00" />
<Msr idx="2" val="71.00" />
</Cell>
<Cell>
<Msr idx="1" val="$158,370.00" />
<Msr idx="2" val="72.00" />
</Cell>
<Cell>
<Msr idx="1" val="$88,594.00" />
<Msr idx="2" val="41.00" />
</Cell>
<Cell>
<Msr idx="1" val="$76,766.00" />
<Msr idx="2" val="37.00" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Braintree Labs">
<RowGrp heading="Braintree Labs">
<Row heading="HalfLytely">
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell>
<Msr idx="1" val="$99,880.00" />
<Msr idx="2" val="18.00" />
</Cell>
<Cell>
<Msr idx="1" val="$538,732.00" />
<Msr idx="2" val="109.00" />
</Cell>
</Row>
<Row heading="Miralax">
<Cell>
<Msr idx="1" val="$818,973.00" />
<Msr idx="2" val="130.00" />
</Cell>
<Cell>
<Msr idx="1" val="$852,424.00" />
<Msr idx="2" val="132.00" />
</Cell>
<Cell>
<Msr idx="1" val="$837,894.00" />
<Msr idx="2" val="133.00" />
</Cell>
<Cell>
<Msr idx="1" val="$847,108.00" />
<Msr idx="2" val="131.50" />
</Cell>
<Cell>
<Msr idx="1" val="$744,838.00" />
<Msr idx="2" val="119.00" />
</Cell>
<Cell>
<Msr idx="1" val="$748,405.00" />
<Msr idx="2" val="123.50" />
</Cell>
<Cell>
<Msr idx="1" val="$421,220.00" />
<Msr idx="2" val="68.50" />
</Cell>
<Cell />
</Row>
<Row heading="NuLytely">
<Cell>
<Msr idx="1" val="$148,537.00" />
<Msr idx="2" val="34.00" />
</Cell>
<Cell>
<Msr idx="1" val="$140,157.00" />
<Msr idx="2" val="33.00" />
</Cell>
<Cell>
<Msr idx="1" val="$143,934.00" />
<Msr idx="2" val="34.00" />
</Cell>
<Cell>
<Msr idx="1" val="$132,831.00" />
<Msr idx="2" val="28.00" />
</Cell>
<Cell>
<Msr idx="1" val="$125,586.00" />
<Msr idx="2" val="37.00" />
</Cell>
<Cell>
<Msr idx="1" val="$166,526.00" />
<Msr idx="2" val="41.00" />
</Cell>
<Cell>
<Msr idx="1" val="$84,466.00" />
<Msr idx="2" val="21.00" />
</Cell>
<Cell>
<Msr idx="1" val="$3,250.00" />
<Msr idx="2" val="2.00" />
</Cell>
</Row>
<Row heading="PhosLo">
<Cell>
<Msr idx="1" val="$254,294.00" />
<Msr idx="2" val="46.00" />
</Cell>
<Cell>
<Msr idx="1" val="$613,311.00" />
<Msr idx="2" val="116.00" />
</Cell>
<Cell>
<Msr idx="1" val="$226,220.00" />
<Msr idx="2" val="40.00" />
</Cell>
<Cell>
<Msr idx="1" val="$29,373.00" />
<Msr idx="2" val="13.00" />
</Cell>
<Cell>
<Msr idx="1" val="$29,817.00" />
<Msr idx="2" val="14.00" />
</Cell>
<Cell>
<Msr idx="1" val="$29,329.00" />
<Msr idx="2" val="15.00" />
</Cell>
<Cell>
<Msr idx="1" val="$29,687.00" />
<Msr idx="2" val="14.00" />
</Cell>
<Cell>
<Msr idx="1" val="$77,964.00" />
<Msr idx="2" val="38.00" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Corixa/Glaxosmithkline Cm">
<RowGrp heading="Corixa/Glaxosmithkline Cm">
<Row heading="Bexxar">
<Cell />
<Cell />
<Cell>
<Msr idx="1" val="$38,661.00" />
<Msr idx="2" val="14.30" />
</Cell>
<Cell>
<Msr idx="1" val="$151,341.00" />
<Msr idx="2" val="58.10" />
</Cell>
<Cell>
<Msr idx="1" val="$85,716.00" />
<Msr idx="2" val="30.30" />
</Cell>
<Cell>
<Msr idx="1" val="$25,520.00" />
<Msr idx="2" val="7.80" />
</Cell>
<Cell />
<Cell />
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Eisai/Janssen Cmkt">
<RowGrp heading="Eisai/Janssen Cmkt">
<Row heading="Aciphex">
<Cell>
<Msr idx="1" val="$184,200.00" />
<Msr idx="2" val="28.00" />
</Cell>
<Cell>
<Msr idx="1" val="$907,177.00" />
<Msr idx="2" val="126.50" />
</Cell>
<Cell>
<Msr idx="1" val="$634,190.00" />
<Msr idx="2" val="90.00" />
</Cell>
<Cell>
<Msr idx="1" val="$589,230.00" />
<Msr idx="2" val="82.00" />
</Cell>
<Cell>
<Msr idx="1" val="$86,653.00" />
<Msr idx="2" val="16.00" />
</Cell>
<Cell>
<Msr idx="1" val="$137,677.00" />
<Msr idx="2" val="25.00" />
</Cell>
<Cell>
<Msr idx="1" val="$52,214.00" />
<Msr idx="2" val="4.00" />
</Cell>
<Cell>
<Msr idx="1" val="$20,844.00" />
<Msr idx="2" val="2.50" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Fleet">
<RowGrp heading="Fleet">
<Row heading="Phospho-Soda Acc-Prp">
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell>
<Msr idx="1" val="$51,303.00" />
<Msr idx="2" val="14.00" />
</Cell>
<Cell>
<Msr idx="1" val="$54,700.00" />
<Msr idx="2" val="18.00" />
</Cell>
<Cell>
<Msr idx="1" val="$33,930.00" />
<Msr idx="2" val="14.00" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Johnson & Johnson">
<RowGrp heading="Janssen Pharma Inc">
<Row heading="Duragesic">
<Cell>
<Msr idx="1" val="$146,689.00" />
<Msr idx="2" val="33.00" />
</Cell>
<Cell>
<Msr idx="1" val="$309,397.00" />
<Msr idx="2" val="64.00" />
</Cell>
<Cell>
<Msr idx="1" val="$671,489.00" />
<Msr idx="2" val="101.40" />
</Cell>
<Cell>
<Msr idx="1" val="$272,694.00" />
<Msr idx="2" val="55.00" />
</Cell>
<Cell>
<Msr idx="1" val="$385,072.00" />
<Msr idx="2" val="62.00" />
</Cell>
<Cell>
<Msr idx="1" val="$478,408.00" />
<Msr idx="2" val="79.00" />
</Cell>
<Cell>
<Msr idx="1" val="$175,135.00" />
<Msr idx="2" val="31.00" />
</Cell>
<Cell>
<Msr idx="1" val="$240,977.00" />
<Msr idx="2" val="35.00" />
</Cell>
</Row>
<Row heading="NPS(Schizophrenia)">
<Cell>
<Msr idx="1" val="$189,314.00" />
<Msr idx="2" val="45.00" />
</Cell>
<Cell>
<Msr idx="1" val="$148,267.00" />
<Msr idx="2" val="35.00" />
</Cell>
<Cell>
<Msr idx="1" val="$62,899.00" />
<Msr idx="2" val="13.00" />
</Cell>
<Cell>
<Msr idx="1" val="$27,556.00" />
<Msr idx="2" val="7.00" />
</Cell>
<Cell>
<Msr idx="1" val="$367,627.00" />
<Msr idx="2" val="55.00" />
</Cell>
<Cell>
<Msr idx="1" val="$5,625.00" />
<Msr idx="2" val="3.00" />
</Cell>
<Cell />
<Cell />
</Row>
<Row heading="Reminyl">
<Cell>
<Msr idx="1" val="$14,730.00" />
<Msr idx="2" val="8.00" />
</Cell>
<Cell>
<Msr idx="1" val="$438,017.00" />
<Msr idx="2" val="66.00" />
</Cell>
<Cell>
<Msr idx="1" val="$699,002.00" />
<Msr idx="2" val="104.00" />
</Cell>
<Cell>
<Msr idx="1" val="$474,523.00" />
<Msr idx="2" val="72.00" />
</Cell>
<Cell>
<Msr idx="1" val="$311,986.00" />
<Msr idx="2" val="48.00" />
</Cell>
<Cell>
<Msr idx="1" val="$452,386.00" />
<Msr idx="2" val="76.00" />
</Cell>
<Cell>
<Msr idx="1" val="$337,346.00" />
<Msr idx="2" val="56.00" />
</Cell>
<Cell>
<Msr idx="1" val="$341,023.00" />
<Msr idx="2" val="54.00" />
</Cell>
</Row>
<Row heading="Risperdal">
<Cell>
<Msr idx="1" val="$124,124.00" />
<Msr idx="2" val="27.00" />
</Cell>
<Cell>
<Msr idx="1" val="$270,330.00" />
<Msr idx="2" val="76.00" />
</Cell>
<Cell>
<Msr idx="1" val="$282,428.00" />
<Msr idx="2" val="70.00" />
</Cell>
<Cell>
<Msr idx="1" val="$133,316.00" />
<Msr idx="2" val="31.00" />
</Cell>
<Cell>
<Msr idx="1" val="$783,270.00" />
<Msr idx="2" val="110.00" />
</Cell>
<Cell>
<Msr idx="1" val="$910,518.00" />
<Msr idx="2" val="138.10" />
</Cell>
<Cell>
<Msr idx="1" val="$418,510.00" />
<Msr idx="2" val="72.80" />
</Cell>
<Cell>
<Msr idx="1" val="$254,860.00" />
<Msr idx="2" val="49.30" />
</Cell>
</Row>
<Row heading="Risperdal Consta">
<Cell />
<Cell />
<Cell />
<Cell>
<Msr idx="1" val="$29,752.00" />
<Msr idx="2" val="6.00" />
</Cell>
<Cell>
<Msr idx="1" val="$963,797.00" />
<Msr idx="2" val="203.00" />
</Cell>
<Cell>
<Msr idx="1" val="$587,537.00" />
<Msr idx="2" val="139.00" />
</Cell>
<Cell>
<Msr idx="1" val="$332,762.00" />
<Msr idx="2" val="73.00" />
</Cell>
<Cell>
<Msr idx="1" val="$289,979.00" />
<Msr idx="2" val="64.00" />
</Cell>
</Row>
<Row heading="Risperdal M-Tab">
<Cell />
<Cell>
<Msr idx="1" val="$116,100.00" />
<Msr idx="2" val="19.00" />
</Cell>
<Cell>
<Msr idx="1" val="$150,000.00" />
<Msr idx="2" val="27.00" />
</Cell>
<Cell>
<Msr idx="1" val="$88,052.00" />
<Msr idx="2" val="19.00" />
</Cell>
<Cell>
<Msr idx="1" val="$22,126.00" />
<Msr idx="2" val="5.00" />
</Cell>
<Cell>
<Msr idx="1" val="$31,940.00" />
<Msr idx="2" val="6.00" />
</Cell>
<Cell>
<Msr idx="1" val="$250,571.00" />
<Msr idx="2" val="36.00" />
</Cell>
<Cell>
<Msr idx="1" val="$167,480.00" />
<Msr idx="2" val="23.00" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Medimmune/Ross Comkt">
<RowGrp heading="Medimmune/Ross Comkt">
<Row heading="Synagis">
<Cell />
<Cell>
<Msr idx="1" val="$35,530.00" />
<Msr idx="2" val="4.00" />
</Cell>
<Cell>
<Msr idx="1" val="$153,681.00" />
<Msr idx="2" val="34.00" />
</Cell>
<Cell>
<Msr idx="1" val="$287,795.00" />
<Msr idx="2" val="79.00" />
</Cell>
<Cell>
<Msr idx="1" val="$78,425.00" />
<Msr idx="2" val="22.00" />
</Cell>
<Cell />
<Cell>
<Msr idx="1" val="$10,970.00" />
<Msr idx="2" val="4.00" />
</Cell>
<Cell>
<Msr idx="1" val="$64,845.00" />
<Msr idx="2" val="22.00" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Merck & Company, Inc">
<RowGrp heading="Merck & Company, Inc">
<Row heading="Vioxx">
<Cell>
<Msr idx="1" val="$1,755,358.00" />
<Msr idx="2" val="264.70" />
</Cell>
<Cell>
<Msr idx="1" val="$500,236.00" />
<Msr idx="2" val="73.30" />
</Cell>
<Cell />
<Cell />
<Cell>
<Msr idx="1" val="$689,037.00" />
<Msr idx="2" val="94.00" />
</Cell>
<Cell>
<Msr idx="1" val="$600,348.00" />
<Msr idx="2" val="86.70" />
</Cell>
<Cell>
<Msr idx="1" val="$252,967.00" />
<Msr idx="2" val="33.10" />
</Cell>
<Cell>
<Msr idx="1" val="$103,545.00" />
<Msr idx="2" val="20.10" />
</Cell>
</Row>
</RowGrp>
</RowGrp>
<RowGrp heading="Mission Pharmacal Co">
<RowGrp heading="Mission Pharmacal Co">
<Row heading="Citracal Prenatal Rx">
<Cell>
<Msr idx="1" val="$3,080.00" />
<Msr idx="2" val="1.00" />
</Cell>
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell>
<Msr idx="1" val="$7,910.00" />
<Msr idx="2" val="1.00" />
</Cell>
</Row>
<Row heading="Urocit-K">
<Cell>
<Msr idx="1" val="$33,886.00" />
<Msr idx="2" val="6.70" />
</Cell>
<Cell>
<Msr idx="1" val="$27,960.00" />
<Msr idx="2" val="6.00" />
</Cell>
<Cell>
<Msr idx="1" val="$27,960.00" />
<Msr idx="2" val="6.00" />
</Cell>
<Cell>
<Msr idx="1" val="$33,000.00" />
<Msr idx="2" val="7.50" />
&n
|