cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT - Data Validation/Manipulation in structures with repetitions

RafaelVieira
Active Participant
0 Kudos

Hi experts,

I have a requirement to validate a field content which is within a 1..N structure, so the data come in pairs of RESULT_ID and RESULT_VALUE.

If "<" (&lt;) is found in Result.Min_Limit characteristic, its value must be put in the Max_Limit characteristic target field and Min_Limit must be cleared out in target structure.

Source structure with data:

<?xml version="1.0" encoding="UTF-8"?>

<TEST>

  <RESULTS>

       <RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.Derived</D_RESULT_ID>

                 <D_RESULT_VALUE>59W</D_RESULT_VALUE>

            </D_RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.Min_Limit</D_RESULT_ID>

                 <D_RESULT_VALUE>&lt;=600.0000</D_RESULT_VALUE>

            </D_RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.Max_Limit</D_RESULT_ID>

                 <D_RESULT_VALUE/>

            </D_RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.FailedCriticalLvl</D_RESULT_ID>

                 <D_RESULT_VALUE>false</D_RESULT_VALUE>

            </D_RESULT>

       </RESULT>

  </RESULTS>

</TEST>

Target must be as follow:

<?xml version="1.0" encoding="UTF-8"?>

<TEST>

  <RESULTS>

       <RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.Derived</D_RESULT_ID>

                 <D_RESULT_VALUE>59W</D_RESULT_VALUE>

            </D_RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.Min_Limit</D_RESULT_ID>

                 <D_RESULT_VALUE/>

            </D_RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.Max_Limit</D_RESULT_ID>

                 <D_RESULT_VALUE>&lt;=600.0000</D_RESULT_VALUE>

            </D_RESULT>

            <D_RESULT>

                 <D_RESULT_ID>Result.FailedCriticalLvl</D_RESULT_ID>

                 <D_RESULT_VALUE>false</D_RESULT_VALUE>

            </D_RESULT>

       </RESULT>

  </RESULTS>

</TEST>



I've created a variable to store Min_Limit value if it contains the "<" character, and it works fine when the pointer is still in Min_Limit characteristic.

When it flips to next characteristic (Max_Limit), the variable seems to loose its value and therefore I have no visibility of Min_Limit value anymore to assign the value to Max_Limit characteristic.


Not sure if it's well explained, but basically I believe I would be able to solve this puzzle if only I had a global variable to assign Min_Limit and then validate it when Max_Limit comes, but I know there's no Global variable in XSL.


Would anyone suggests an alternative to solve this?


Many thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Rafael,

You can use the same variables used in XSLT mapping in ABAP proxy coding to clear the variable before its second use.

Regards,

Souvik

Answers (1)

Answers (1)

RafaelVieira
Active Participant
0 Kudos

Any suggestion?

Although I haven't find any good thread to help with this issue, it seems to be something little straightforward to be resolved.

Any help would be greatly appreciated.

Tks!

iaki_vila
Active Contributor
0 Kudos

Hi Rafael,

I have tried with XSLT but you can't assign values to the variables twice, when you define one you assign the value in that moment. If you set the value inside a for:each, the variable has not been defined properly because in in the selection to ask its value can occurs that the variable has not defined yet.

From my opinion you should try to do an UDF inside a message mapping.

Regards.

RafaelVieira
Active Participant
0 Kudos

Thanks for the inputs.


However, it's an XSLT mapping which is already in production. So unfortunately I don't have the option of defining a new msg mapping with a Java UDF.

I've used the global variable concept just as an example of fix to the issue but I believe there should have another way of resolving it since it's such a basic/common need that XSLT should do much more easier than the graphical one.

Input

<?xml version="1.0" encoding="UTF-8"?>

<root>

  <structure>

  <ID>11</ID>

  <VALUE>111</VALUE>

  </structure>

  <structure>

  <ID>NAME</ID>

  <VALUE>NON</VALUE>

  </structure>

  <structure>

  <ID>OTHER</ID>

  <VALUE>XXX</VALUE>

  </structure>

...

</root>

Rule for field VALUE when ID="NAME":

  IF //structure/ID="11" and VALUE="111"

  THEN field //structure/VALUE = structure/VALUE (ref. ID 11, which is "111")

  OTHERWISE field <VALUE> = structure/VALUE (ref. ID NAME, which is "NON")

Expected output

<?xml version="1.0" encoding="UTF-8"?>

<root>

<structure>

  <ID>11</ID>

  <VALUE>111</VALUE>

  </structure>

  <structure>

  <ID>NAME</ID>

  <VALUE>111</VALUE>

  </structure>

  <structure>

  <ID>OTHER</ID>

  <VALUE>XXX</VALUE>

  </structure>

...

</root>

I'd like to hear your opinions on how to write something to handle this.

Thanks!