Re: [xsl] Missing nodes are ruining my sort !!!!

Subject: Re: [xsl] Missing nodes are ruining my sort !!!!
From: "Rupert Howell" <Rupert.Howell@xxxxxxxxxxxxxx>
Date: Tue, 9 Dec 2003 13:17:16 +0000
Dear all.

I'm sorry if this a long-winded explanation of my problem - I have been
stuck on this for weeks and the answer isn't in any books or forums.
Its tricky to explain but here we go ....

I have some XML that is produced from a database and it looks something
like this.


<RESULTS>
<PRESENTATION>
  <AREAS>
     <AREA areaid='A'>London</AREA>
     <AREA areaid='B'>North East</AREA>
     <AREA areaid='C'>North West</AREA>
     <AREA areaid='D'>South East</AREA>
  </AREAS>
  <VARIABLES>
     <VARIABLE variableid='1'>Variable1</VARIABLE>
     <VARIABLE variableid='2'>Variable2</VARIABLE>
     <VARIABLE variableid='3'>Variable3</VARIABLE>
     <VARIABLE variableid='4'>Variable4</VARIABLE>
  </VARIABLES>
</PRESENTATION>

<DATA>
  <INSTANCE>
     <AREAID>A</AREAID>
     <VARIABLEID>1</VARIABLEID>
     <VALUE>100</VALUE>
  </INSTANCE>
  <INSTANCE>
     <AREAID>B</AREAID>
     <VARIABLEID>1</VARIABLEID>
     <VALUE>200</VALUE>
  </INSTANCE>
  <INSTANCE>
     <AREAID>D</AREAID>
     <VARIABLEID>1</VARIABLEID>
     <VALUE>300</VALUE>
  </INSTANCE>

  <INSTANCE>
     <AREAID>A</AREAID>
     <VARIABLEID>2</VARIABLEID>
     <VALUE>400</VALUE>
  </INSTANCE>
  <INSTANCE>
     <AREAID>B</AREAID>
     <VARIABLEID>2</VARIABLEID>
     <VALUE>500</VALUE>
  </INSTANCE>
  <INSTANCE>
     <AREAID>D</AREAID>
     <VARIABLEID>2</VARIABLEID>
     <VALUE>600</VALUE>
  </INSTANCE>

  <INSTANCE>
     <AREAID>A</AREAID>
     <VARIABLEID>3</VARIABLEID>
     <VALUE>700</VALUE>
  </INSTANCE>
  <INSTANCE>
     <AREAID>B</AREAID>
     <VARIABLEID>3</VARIABLEID>
     <VALUE>800</VALUE>
  </INSTANCE>
  <INSTANCE>
     <AREAID>D</AREAID>
     <VARIABLEID>3</VARIABLEID>
     <VALUE>900</VALUE>
  </INSTANCE>
</DATA>

</RESULTS>

The PRESENTATION node of the XML contains all the AREAS and VARIABLES that
MUST be placed in a table.
It must be noted that there is not neccessarily data instance node for each
corresponding area id. In which case you would
expect to see a blank cell.

I am therefore recursing through the PRESENTATION children nodes and
getting the actual values of $areaid and $variableid
then using  xpath
RESULTS/DATA/INSTANCE/AREAID[text()=$areaid]/../VARIABLEID[text()=$variableid]/../VALUE/textt()
 to
get the values.

So from this I am producing a table :

               Variable1      Variable2      Variable3

London           100          400         600
North East          200         500          800
North West
South East          300         600          900


This is working fine and by rigidly recursing through the presentation node
firs,t I am able to get the blank values.

The problem lies in sorting the table.
To sort the values I have to actually have to have the values selected. In
which case the sort works fine, but my blank row just disappears.

So basically my question is : -

How can I sort the //PRESENTATION/AREAS/AREA dependant on its value in
/DATA/INSTANCE/VALUE, and if the value is non existant,
still include it in the sort?

Any help would be hugely appreciated.

Rupert









For the latest data on the economy and society 
consult National Statistics at http://www.statistics.gov.uk

**********************************************************************
Please Note:  Incoming and outgoing email messages
are routinely monitored for compliance with our policy
on the use of electronic communications
**********************************************************************
Legal Disclaimer  :  Any views expressed by
the sender of this message are not necessarily
those of the Office for National Statistics
**********************************************************************

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread