Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Transformation - ignore attribute in element

JanBraendgaard
Active Participant
0 Kudos

I am trying to create a Simple Transformation, but am stuck with the issue of having to ignore an attribute in the root element.

This is my XML data:

<?xml version="1.0" encoding="utf-8"?>
<ExportData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="PostProcessor.SaveToXML" rootItemNumber="503620-000">
  <TimeStamp>2021-12-22T09:30:42.927665+01:00</TimeStamp>
  <Items>
    <Item>
      <ItemNumber type="String" value="061243-JBP"/>
      <VersionNumber type="Numeric" value="9"/>
    </Item>
  </Items>
</ExportData>

I would like to ignore or skip the attribute "rootItemNumber".

I'm using the ST code below.

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root name="EXPORTDATA" type="ddic:ZCA_EXPORTDATA"/>
<tt:template>
<ExportData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" rootItemNumber="503620-000" xmlns="NTI.Vault.Pro.BOMExport.PostProcessor.SaveToXML">
<TimeStamp tt:value-ref=".EXPORTDATA.TIMESTAMP"/>
<Items>
<tt:loop ref=".EXPORTDATA.ITEM">
<Item>
<ItemNumber>
<tt:attribute name="value" value-ref="ITEMNUMBER"/>
</ItemNumber>
<VersionNumber>
<tt:attribute name="value" value-ref="VERSIONNUMBER"/>
</VersionNumber>
</Item>
</tt:loop>
</Items>
</ExportData>
</tt:template>
</tt:transform>
4 REPLIES 4

Sandra_Rossi
Active Contributor
0 Kudos

Just this?

            <ItemNumber>
<tt:cond>
<tt:attribute name="value"/>
</tt:cond>
</ItemNumber>

JanBraendgaard
Active Participant
0 Kudos

Hello sandra.rossi

I changed the attributes to conditional as you suggested. But this throws an error with "System expected element '<ExportData>'".

I think that this is because the ST code has no attributes in the <ExportData> element, and the XML contains four attributes in the element?

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined" >
<tt:root name="EXPORTDATA" type="ddic:ZCA_VAULT_EXPORTDATA"/>
<tt:template>
<!-- <ExportData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" rootItemNumber="503620-000" xmlns="SaveToXML">-->
<ExportData>
<tt:cond>
<tt:attribute name="xsd"/>
<tt:attribute name="xsi"/>
<tt:attribute name="rootItemNumber" value-ref=".EXPORTDATA.ROOTITEMNUMBER"/>
<tt:attribute name="xmlns"/>
</tt:cond>

Sandra_Rossi
Active Contributor
0 Kudos

You don't need to indicate <tt:attribute...> for the attributes defining the namespaces.

You probably have an issue with the element <ExportData> which belongs to the namespace URI "SaveToXML".

    ...
    <xyz:ExportData xmlns:xyz="SaveToXML" >
      ...

JanBraendgaard
Active Participant

Thank you sandra.rossi ,

This led me on the right track. And now it works. I added namespace to the elements.

And I also noticed that the test-XML-file I had been supplied with was missing three additional elements, that I had expected in the ST program. This also led me astray 🙂