Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: How to conditionally combine XML elements with rules How to conditionally combine XML elements with rulesTo: NULL Date: 2/20/2009 6:29:00 AM Suppose I have input xml like following: Element #1. <serial-port port=3D"port1" type=3D"control" baud=3D"38400" parity=3D"none"= /> Element #2. //differ in @type with element #1. <serial-port port=3D"port1" type=3D"status" baud=3D"38400" parity=3D"none"/= > Element #3. //same as element #2. <serial-port port=3D"port1" type=3D"status" baud=3D"38400" parity=3D"none"/= > Element #4. <serial-port port=3D"port1" type=3D"relay" baud=3D"38400" parity=3D"none"/> Element #5. //differ in @baud with element #2. <serial-port port=3D"port1" type=3D"status" baud=3D"115200" parity=3D"none"= /> Element #6. <serial-port port=3D"port2" type=3D"relay" baud=3D"115200" parity=3D"none"/= > Base on my rules at the end, I wound like to have desired output as following. Note there are 6-input elopements and resulting 5-output elements with Element #1 and #2 being combined into one. How can this be done with XSLT? <SerialPort> //Combines Element #1 and #2: rules 2.0 and 2.1 <Port>port1</Port> <Type>status-control</Type> //control-status also OK, they are to //be treated the same in parsing program. <Baud>38400</Baud> <Parity>none</Parity> </SerialPort> <SerialPort> //Element #3. Although it is qualified to be combined with element #1 in the output, //due to the fact that Element #1 has been taken. Leave alone per rule 2.2 <Port>port1</Port> <Type>status </Type> <Baud>38400</Baud> <Parity>none</Parity> </SerialPort> <SerialPort> //Element 4. Leave alone per rule 2.1 - @type of 'relay' can't be combined with others. <Port>port1</Port> <Type>relay</Type> <Baud>38400</Baud> <Parity>none</Parity> </SerialPort> <SerialPort> //Element 5. Leave alone per rule 2.0 - not matching @Baud for 'port1' with @type of 'control'. <Port>port1</Port> <Type>status</Type> <Baud>115200</Baud> <Parity>none</Parity> </SerialPort> <SerialPort> //Element 6. Leave alone per rule 2.1 - @type of 'relay' can't be combined with others. //Or rule 2.0 - there is no other <serial-port> with same @port. <Port>port2</Port> <Type>relay</Type> <Baud>115200</Baud> <Parity>none</Parity> </SerialPort> Here are my rules: 1.0 @type has valid values of: status, control, and relay. 2.0 Only <serial-port> of same @port (the key), @baud, and @parity can be combined. And, 2.1 The two to be combined elements must have different @type, and the @type must be either =91status=92 or =91control=92. And, 2.2 Each <serial-port> can be combined only once. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
