Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Manipulate XML

Avatar

Level 7

I want to convert from XML1 to XML2. Is it possible to do this through set value? Or, do I have to write a custom script? I want to group the repeating elements by the id and merge it with the form as buckets of data...

XML1

<form1>

     <Details>

          <id>1</id>

          <firsntname>example1</firstname>

          <lastname>example1</lastname>

     </Details>

          <Details>

          <id>2</id>

          <firsntname>example2</firstname>

          <lastname>example2</lastname>

     </Details>

     <Details>

          <id>1</id>

          <firsntname>example3</firstname>

          <lastname>example3</lastname>

     </Details>

     <Details>

          <id>3</id>

          <firsntname>example4</firstname>

          <lastname>example4</lastname>

     </Details>

</form1>

XML2

<form1>

     <Details>

          <id>1</id>

          <firsntname>example1</firstname>

          <lastname>example1</lastname>

      </Details>

     <Details>

          <id>1</id>

          <firsntname>example3</firstname>

          <lastname>example3</lastname>

     </Details>

</form1>

Aditya

11 Replies

Avatar

Level 10

This is not easily done with the setValue.

You're better off using the Execute Script or your own custom component to do that.

This is something we would like to improve.

Sorry.

Jasmin

Avatar

Level 7

Do you have any sample scripts to do that? I am thinking of using the API to create the XML. Wasn't sure if it would affect the performance of the server.

Thanks

Aditya

Avatar

Employee

Actually, I would recommend using the XSLT service with a stylesheet for something like this. A custom DSC or script seems like overkill.

Avatar

Level 7

Thanks! Do any one of you know a good resource on XSLT? I have never worked with them before...

Aditya

Avatar

Employee

A good beginner resource can be found here:  http://www.w3schools.com/xsl/

I could write you a sample, but I am not sure what you want to accomplish. You just want every ID to be 1?

Avatar

Level 7

Correct! I am trying to create buckets of XML by the id and merge it with the PDF. Hence, the three XMLs should be created in the following order id=1, id=2, id=3.

I am not sure, if XSLT will allow loops...

Aditya

Avatar

Employee

When you say "three XMLs" do you mean seperate files or simply seperate nodes in one XML file?

Avatar

Employee

The plot thickens....

Let's see what we can do

Avatar

Level 7

Below works for me...

I will have to create a loop anyway to create each XML merge it with the PDF. Thanks a lot for your help!

Aditya