0

Currently, for all elements where we have mentioned namespace prefix "etd", link is printed for them (highlighted green). Output XML file looks like: enter image description here

I want output to look like: enter image description here

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>
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Shreya
  • 3
  • 3
  • 1
    Please post a **reproducible** example, including an input, your current XSLT stylesheet, and the expected output **as code**, not as picture. What you're showing above is not a "transformation* - in fact, it's not even a well-formed XML document. Note also that the placement of a namespace declaration and the number of times it repeats has no significance and should not make any difference to the receiving application. – michael.hor257k Apr 24 '17 at 11:13

2 Answers2

0

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.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I have updated my question. Please find my complete code, and provide me your inputs to resolve the issue. – Shreya Apr 26 '17 at 05:13
  • Your code appears to be written in some SAP transformation language that resembles XSLT, but is not actually XSLT. I don't know this SAP language so I can't help you. – Michael Kay Apr 26 '17 at 07:38
  • Yes, its an SAP Transformation. No problem, thank you for your time and response :) – Shreya Apr 26 '17 at 09:53
0

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>
szako
  • 1,271
  • 1
  • 9
  • 12
  • Thank you, it solved my issue :) I would really appreciate if you could help me one more time. Is it possible to prevent empty tags from printing in XML file, if that field has no value? For example: Currently a specific section of XML is displayed as: 2016-04-19 2016-04-19 1.000,00 1.000,00 I do not want empty tags for K_10, K_13 and K_14 to be displayed in XML file since they have no value. Thank you in advance for your time and advice. – Shreya Apr 28 '17 at 05:20
  • Use [conditional transformations](https://help.sap.com/saphelp_erp60_sp/helpdata/en/0c/402040abf2c442e10000000a1550b0/content.htm). There's a "not-initial" condition for checking. Example in the first comment in [this](https://archive.sap.com/discussions/thread/2043498) thread. – szako Apr 29 '17 at 06:17
  • Thank you for your response, but i am sorry i could not understand/find the exact syntax to be used. I would appreciate if you could share the above code with Conditional transformation for any one of the field. Thank you in advance for your help – Shreya May 01 '17 at 13:18
  • The OP on the linked SCN question wanted exactly the same what you want. In the first reply you can see the example: ` ` – szako May 02 '17 at 08:44
  • Thank you, I already tried using this statement and is working perfect when node has no value. That specific node is not displayed in XML as expected. But my case is: I want to hide parent node when none of the child node has value. For clarity,in your example if BUKRS, ANLN1 and ANLN2 have no value at the same time, i want to hide parent node "ANLA" also, along with 3 fields separately. Entire tree should be hidden. Currently, root node 'ANLA' is displayed What condition could i use for this purpose, since parent is not related to any field specifically (ex- "ZSOURCE"). – Shreya May 04 '17 at 07:48
  • Isn't there an "AND" operator? – szako May 04 '17 at 08:09
  • Did you mean to use "AND" operator for conditions of all child nodes? – Shreya May 04 '17 at 11:06
  • Yes I meant that. – szako May 05 '17 at 04:46