Application Development and Automation 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: 

how to set a constant attribute to strans xml transformation?

Former Member
0 Kudos
1,275

Hi,experts.
How to set a constant attribute to xml transformation.
For example i have only sender field and want to get an xml = <issuance xmlns="http://www.w3schools.com" sender="700069297">

</issuance>

I found how to set an sender attribute by ref, but how to set a constant of xmlns?

 

 

<?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="ROOT" type="ddic:ZVA_ESCHF_GET"/>
  <tt:template>
    <issuance>
       
       <tt:attribute name="sender" value-ref="ROOT.SENDER"/>
    </issuance>
  </tt:template>
</tt:transform>

 

 

 

8 REPLIES 8

Sandra_Rossi
Active Contributor
0 Kudos
1,232

Why would you want to define a namespace as a variable? Transformations refer 99.9% of the time to fixed namespaces. If you want a special transformation, completely dynamic, use XSLT.

0 Kudos
1,213

What do u mean by "namespace variable", sender is always different, xmlns is always the same, should i use xslt?

1,164

No. If it's a constant namespace, did you try this directly in the simple transformation?

<issuance xmlns="http://www.w3schools.com">

 

0 Kudos
1,061

in that case i couldn't get a closing 
</issuance> tag

0 Kudos
1,052

I couldn't get a closing tag even withount xmlns tag :
Mine xml, i want to get : <issuance sender="700069297"></issuance>
mine trans : 

 

 

 

<?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="ROOT" type="ddic:ZVA_ESCHF_GET"/>
  <tt:template>
    <issuance>

       <tt:attribute name="sender" value-ref="ROOT.SENDER"/>
    </issuance>
  </tt:template>
</tt:transform>

 

 

 

0 Kudos
1,048

I guess you want to obtain this:

 

<issuance xmlns="http://www.w3schools.com" sender="700069297">
</issuance>

 

Your expectation is incorrect, both forms are valid and strictly identical, and will be accepted by all the XML readers I know.

There's no way you can obtain the end tag.

0 Kudos
970

Ok, but what if some of xml documents have different headers?
For example 
1)

<issuance xmlns="http://www.w3schools.com" sender="400052406">

2)

<issuance xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3schools.com" xsi:schemaLocation="http://www.w3schools.com" sender="300062307">

only 'sender' is attribute, as i understand.
How to setup an  xml transformation in this case?

0 Kudos
936

Why would you want to define a namespace as a variable? Transformations refer 99.9% of the time to fixed namespaces. If you want a special transformation, completely dynamic, use XSLT.