Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


How to conditionally combine XML elements with rules

From: "hq4000@-------.---" <------@-------.--->
To: 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.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent