cancel
Showing results for 
Search instead for 
Did you mean: 

Repeat Root element for each child element XSLT

Former Member
0 Kudos

I need to repeat the top level element for each child element.

My structure is

<Sensor xmlns=namespace>

<Observation>

<XML> some data </XML>

</Observation>

</Sensor

Observation is 1:n, I need sensor to repeat every observation.

Currently i have for-each loop that places the document in the following structure

<Sensor xmlns=namespace>

<Observation>

<XML> some data </XML>

</Observation>

<Observation>

<XML> some data </XML>

</Observation>

<Observation>

<XML> some data </XML>

</Observation>

<Observation>

<XML> some data </XML>

</Observation>

</Sensor>

How do I get Sensor to repeat without error? I am using XSLT.

I get this error when i tried puting sensor tag part of the loop

Only one top level element is allowed in an XML document. Error processing resource 'file:///...

<pmlcore:Sensor xmlns:pmlcore="urn:autoid:specification:interchange:PMLCore:xml:schema:1" xmlns:pmluid="urn:autoid:specif...

Accepted Solutions (0)

Answers (4)

Answers (4)

udo_martens
Active Contributor
0 Kudos

Hi,

if you want to repeat the sensor element, you need to create a new root element.

Regards,

Udo

Former Member
0 Kudos

Hi,

Why not create a parameter from the root element which you want to present in each line. and include this entry in the target elements.

If you need a code snipplet let me know

Greets

Former Member
0 Kudos

yes can please give me code snipet

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi chirag,

If you are using XSLT Mapping use loop statement,how to use loop statement open w3schools.com ,

you wil find XSLT Docs and how to use.

Regards,

Raj

Former Member
0 Kudos

yes i have already used looping for the observation part.

I just need the Sensor top node to repeat.

for each observation

Former Member
0 Kudos

Used OneAsMany function in graphical Mapping.

This splits the file by setting Sensor 0..unbound.

Each Observation has Sensor.

Former Member
0 Kudos

hi chirag,

i think u cant repeat ur sensor tag in same XML.

Xi follow soap xml message format . It has following tags

1) Soap envelop

2) Soap header

3) Soap body

The required SOAP Envelope element is the root element of a SOAP message. This element defines the XML document as a SOAP message. And root always having occurrence 1.

The optional SOAP Header element contains application-specific information (like authentication, payment, etc) about the SOAP message. If the Header element is present, it must be the first child element of the Envelope element

The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message. Its may occur may times.

And if u r trying to make many soap envelop(sensor) than it is not possible . for this u need to break this message in individual xml messages.

Regards, navneet