laptop_01 Posted October 18, 2003 Posted October 18, 2003 I am converting a legacy binary DB to XML. The DB is mostly used to store numeric arrays. Using array Temperature (x,y,z) as an example: Temperature(1,1,1) = 99.4 Temperature(1,1,2) = 100.4 Temperature(1,1,3) = 200.4 ...... and so forth I am wondering what is the best way to model this? I am currently using this XML Tag plus XSLT to format the data: <DS Name="NTCBDS" > <Value D1="1" D2="1" D3="1"> 99.4 </Value> <Value D1="1" D2="1" D3="2"> 100.2 </Value> <Value D1="1" D2="1" D3="3"> 200.1 </Value> <Value D1="1" D2="2" D3="1"> 190.3 </Value> ........ ans so forth </DS> Sometimes, I will need to query the data based on D1, or D2, or D3. For example, I may ask for all data values where D3=5 (ie, select all values where D3=5 (fixed), D1 goes from 1 to MAX and D2 goes from 1 to MAX). Question: Is the above model good or fit for such search using XSL. If yes, could you give a sample XSL to do the scenario I mentioned above. I don't seem to be able to get it right. OR should I be using: <DS Name="NTCBDS" > <Value> <D1>"1"</D1> <D2>"1"</D2> <D3>"1"</D3> 99.4 </Value> <Value> <D1>"1"</D1> <D2>"1"</D2> <D3>"2"</D3> 100.2 </Value> <Value> <D1>"1"</D1> <D2>"1"</D2> <D3>"3"</D3> 200.1 </Value> </DS> With the assumption that since D1,D2 and D3 are now elements, I may have more template power ... I am semi new to XSLT. Thanks Quote
XyBoy Posted October 29, 2003 Posted October 29, 2003 I don't think it makes much of difference. Have a look at the XPath specs or at a tutorial. I haven't been writing XSL for some time, but as far as I can remember, you can use XPath expressions with the XML DOM, like this : yourXMLDocument.SelectNodes (XPathExpression) -> it returns all the nodes that match the expression. XPath allows you to select a node based on its attributes and/or on its parents/children nodes values. For instance, your XPath expression would be something like : 1. for the first structure you described : /DS/Value[@D1=x AND @D2=y] (returns the nodes of type "Value" that have a parent of type "DS" that is at the root of the doc AND for which the D1 attribute equals x and the D2 attribute equals y; I'm not sure of the "AND" syntax, look at the specs). 2. for the second structure : /DS/Value[D1=1 AND D2=2] (the same, but D1 and D2 are children, not attributes). Note : I don't think you need the double-quotes in your XML file : <D3>3</D3> is ok. Hope this helps. To adapt this to an XSLT file, it's not very difficult. I can show you an example if you want. Bye. Xyboy. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.