简体   繁体   中英

Use multiple namespaces in single XML element through ABAP Simple Transformation

Currently, for all elements where we have mentioned namespace prefix "etd", link is printed for them (highlighted green). Output XML file looks like:在此处输入图片说明

I want output to look like:在此处输入图片说明

Instead of printing link for all elements, I want it to print only once - at header (in element "JPK", highlighted green), like the default namespace.

Could you please provide me your valuable inputs to correct the issue?

Please find the code of my Simple Transformation created through transaction code XSLT_TOOL :

<?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="?"/>
  <tt:root name="VAT_DATA" type="ddic:ZZCVAT_DECLARATION_MAIN"/>
  <tt:template>
    <JPK xmlns="http://jpk.mf.gov.pl/wzor/2016/03/09/03094/"
         xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/">
      <NAGLOWEK>
        <KODFORMULARZA kodSystemowy="JPK_VAT (2)" tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.KODFORMULARZA" wersjaSchemy="1-0"/>
        <WARIANTFORMULARZA tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.WARIANTFORMULARZA"/>
        <CELZLOZENIA tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.CELZLOZENIA"/>
        <DATAWYTWORZENIAJPK tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.DATAWYTWORZENIAJPK"/>
        <DATAOD tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.DATAOD"/>
        <DATADO tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.DATADO"/>
        <DOMYSLNYKODWALUTY tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.DOMYSLNYKODWALUTY"/>
        <KODURZEDU tt:value-ref=".VAT_DATA.JPK.NAGLOWEK.KODURZEDU"/>
      </NAGLOWEK>
      <PODMIOT1>
        <IDENTYFIKATORPODMIOTU>
          <etd:NIP tt:value-ref=".VAT_DATA.JPK.PODMIOT1.IDENTYFIKATORPODMIOTU.NIP"/>
          <etd:PELNANAZWA tt:value-ref=".VAT_DATA.JPK.PODMIOT1.IDENTYFIKATORPODMIOTU.PELNANAZWA"/>
          <etd:REGON tt:value-ref=".VAT_DATA.JPK.PODMIOT1.IDENTYFIKATORPODMIOTU.REGON"/>
        </IDENTYFIKATORPODMIOTU>
        <ADRESPODMIOTU>
          <etd:KODKRAJU tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.KODKRAJU"/>
          <etd:WOJEWODZTWO tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.WOJEWODZTWO"/>
          <etd:POWIAT tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.POWIAT"/>
          <etd:GMINA tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.GMINA"/>
          <etd:ULICA tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.ULICA"/>
          <etd:NRDOMU tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.NRDOMU"/>
          <etd:MIEJSCOWOSC tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.MIEJSCOWOSC"/>
          <etd:KODPOCZTOWY tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.KODPOCZTOWY"/>
          <etd:POCZTA tt:value-ref=".VAT_DATA.JPK.PODMIOT1.ADRESPODMIOTU.POCZTA"/>
        </ADRESPODMIOTU>
      </PODMIOT1>
      <tt:loop ref=".VAT_DATA.JPK.SPRZEDAZWIERSZ">
        <SPRZEDAZWIERSZ typ="G">
          <LPSPRZEDAZY tt:value-ref="LPSPRZEDAZY"/>
          <NRKONTRAHENTA tt:value-ref="NRKONTRAHENTA"/>
          <NAZWAKONTRAHENTA tt:value-ref="NAZWAKONTRAHENTA"/>
          <ADRESKONTRAHENTA tt:value-ref="ADRESKONTRAHENTA"/>
          <DOWODSPRZEDAZY tt:value-ref="DOWODSPRZEDAZY"/>
          <DATAWYSTAWIENIA tt:value-ref="DATAWYSTAWIENIA"/>
          <DATASPRZEDAZY tt:value-ref="DATASPRZEDAZY"/>
          <K_10 tt:value-ref="K_10"/>
          <K_11 tt:value-ref="K_11"/>
          <K_12 tt:value-ref="K_12"/>
          <K_13 tt:value-ref="K_13"/>
          <K_14 tt:value-ref="K_14"/>
          <K_15 tt:value-ref="INNER_STR_31.K_15"/>
          <K_16 tt:value-ref="INNER_STR_31.K_16"/>
          <K_17 tt:value-ref="INNER_STR_32.K_17"/>
          <K_18 tt:value-ref="INNER_STR_32.K_18"/>
          <K_19 tt:value-ref="INNER_STR_33.K_19"/>
          <K_20 tt:value-ref="INNER_STR_33.K_20"/>
          <K_21 tt:value-ref="K_21"/>
          <K_22 tt:value-ref="K_22"/>
          <K_23 tt:value-ref="INNER_STR_34.K_23"/>
          <K_24 tt:value-ref="INNER_STR_34.K_24"/>
          <K_25 tt:value-ref="INNER_STR_35.K_25"/>
          <K_26 tt:value-ref="INNER_STR_35.K_26"/>
          <K_27 tt:value-ref="INNER_STR_36.K_27"/>
          <K_28 tt:value-ref="INNER_STR_36.K_28"/>
          <K_29 tt:value-ref="INNER_STR_37.K_29"/>
          <K_30 tt:value-ref="INNER_STR_37.K_30"/>
          <K_31 tt:value-ref="K_31"/>
          <K_32 tt:value-ref="INNER_STR_38.K_32"/>
          <K_33 tt:value-ref="INNER_STR_38.K_33"/>
          <K_34 tt:value-ref="INNER_STR_39.K_34"/>
          <K_35 tt:value-ref="INNER_STR_39.K_35"/>
          <K_36 tt:value-ref="K_36"/>
          <K_38 tt:value-ref="K_38"/>
          <K_39 tt:value-ref="K_39"/>
        </SPRZEDAZWIERSZ>
      </tt:loop>
      <SPRZEDAZCTRL>
        <LICZBAWIERSZYSPRZEDAZY tt:value-ref=".VAT_DATA.JPK.SPRZEDAZCTRL.LICZBAWIERSZYSPRZEDAZY"/>
        <PODATEKNALEZNY tt:value-ref=".VAT_DATA.JPK.SPRZEDAZCTRL.PODATEKNALEZNY"/>
      </SPRZEDAZCTRL>
      <tt:loop ref=".VAT_DATA.JPK.ZAKUPWIERSZ">
        <ZAKUPWIERSZ typ="G">
          <LPZAKUPU tt:value-ref="LPZAKUPU"/>
          <NRDOSTAWCY tt:value-ref="NRDOSTAWCY"/>
          <NAZWADOSTAWCY tt:value-ref="NAZWADOSTAWCY"/>
          <ADRESDOSTAWCY tt:value-ref="ADRESDOSTAWCY"/>
          <DOWODZAKUPU tt:value-ref="DOWODZAKUPU"/>
          <DATAZAKUPU tt:value-ref="DATAZAKUPU"/>
          <DATAWPLYWU tt:value-ref="DATAWPLYWU"/>
          <K_43 tt:value-ref="INNER_STR_51.K_43"/>
          <K_44 tt:value-ref="INNER_STR_51.K_44"/>
          <K_45 tt:value-ref="INNER_STR_52.K_45"/>
          <K_46 tt:value-ref="INNER_STR_52.K_46"/>
          <K_47 tt:value-ref="K_47"/>
          <K_48 tt:value-ref="K_48"/>
          <K_49 tt:value-ref="K_49"/>
          <K_50 tt:value-ref="K_50"/>
        </ZAKUPWIERSZ>
      </tt:loop>
      <ZAKUPCTRL>
        <LICZBAWIERSZYZAKUPOW tt:value-ref=".VAT_DATA.JPK.ZAKUPCTRL.LICZBAWIERSZYZAKUPOW"/>
        <PODATEKNALICZONY tt:value-ref=".VAT_DATA.JPK.ZAKUPCTRL.PODATEKNALICZONY"/>
      </ZAKUPCTRL>
    </JPK>
  </tt:template>
</tt:transform>

If you want a namespace declaration to appear on a root element rather than on repeated child elements, just make sure that the root element (when you create it) has that namespace in scope.

If you create the element using a literal result element, just add a namespace declaration to the LRE, and it will be copied to the output.

If you create the element using xsl:element (and if you can't switch to using an LRE) then it's a bit more tricky. In XSLT 2.0 you can do it using xsl:namespace.

For more advice, we really need to see your code.

According to the documentation you can achieve this by adding <tt:namespace name="etd" /> after the JPK tag.

Standard behavior is adding namespace to every tag, cited from the linked page:

A namespace declaration is written exactly into the element in which it is needed.

Tried it with a dummy example:

Simple transformation code:

<?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 line-type="ddic:ANLA" name="ROOT"/>
  <tt:template>
    <ROOT xmlns="http://jpk.mf.gov.pl/wzor/2016/03/09/03094/" xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/">
      <tt:namespace name="etd" />
      <tt:loop ref=".ROOT">
        <ANLA>
          <etd:BUKRS tt:value-ref="BUKRS"/>
          <ANLN1 tt:value-ref="ANLN1"/>
          <ANLN2 tt:value-ref="ANLN2"/>
        </ANLA>
      </tt:loop>
    </ROOT>
  </tt:template>
</tt:transform>

XML result:

<?xml version="1.0" encoding="UTF-8"?>
-<ROOT xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/" xmlns="http://jpk.mf.gov.pl/wzor/2016/03/09/03094/">    
    -<ANLA>
        <etd:BUKRS>1000</etd:BUKRS>
        <ANLN1>131234246</ANLN1>
        <ANLN2>0000</ANLN2>
    </ANLA>
</ROOT>

Otherwise (if you don't use the mentioned tag) the result was:

<?xml version="1.0" encoding="UTF-8"?>
-<ROOT xmlns="http://jpk.mf.gov.pl/wzor/2016/03/09/03094/">
   -<ANLA>
      <etd:BUKRS xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/">1000</etd:BUKRS>
      <ANLN1>131234245</ANLN1>
      <ANLN2>0000</ANLN2>
   </ANLA>
</ROOT>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM