क्या आप कृपया xslt का उपयोग करके किसी xml को दूसरे प्रारूप में बदलने में मेरी सहायता कर सकते हैं? मेरे पास एक इनपुट एक्सएमएल है जिसे दूसरे प्रारूप में बदलने की जरूरत है, हालांकि मैंने एक्सएसएलटी का उपयोग करने की कोशिश की, लेकिन व्यर्थ। कृपया मुझे एक नमूना कोड प्रदान करें।

यहाँ स्रोत एक्सएमएल है

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
   <ns0:Message1>
      <STEP-ProductInformation ExportTime="2017-11-03 14:45:02" ExportContext="en-EN" ContextID="en-EN" WorkspaceID="Main" UseContextLocale="false">
         <Products>
            <Product ID="prd_388061006" UserTypeID="obj_product" ParentID="prd_en_10000201">
               <Name>name</Name>
               <ClassificationReference ClassificationID="cls_1_6434100" Type="ref_product_to_erpgroup"/>
               <AssetCrossReference AssetID="173994" Type="ref_primary_product_image"/>
               <Values>
                  <Value AttributeID="atr_ext_var_list_ed_010_KRL">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_010_KRL">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_ed_011_KRS">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_011_KRS">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_nr">388061006</Value>
                  <Value AttributeID="atr_ext_var_list_ed_012_TVR">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_012_TVR">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_sd_013_ELS">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_ed_013_ELS">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_014_PSK">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_sd_015_ODN">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_ed_014_PSK">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_002_KLM">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_sd_003_VLD">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_ed_002_KLM">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_ed_003_VLD">9999-12-31</Value>
                  <Value AttributeID="atr_ext_ar_nr">388061</Value>
                  <Value AttributeID="atr_ext_var_list_ed_004_RYA">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_004_RYA">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_sd_005_YAR">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_sd_006_TUL">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_ed_005_YAR">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_ed_006_TUL">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_ed_001_SCH">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_001_SCH">2017-06-12</Value>
                  <Value AttributeID="atr_ext_var_list_ed_015_ODN">9999-12-31</Value>
                  <Value AttributeID="atr_pt_brand" ID="184985">1977</Value>
                  <Value AttributeID="atr_ext_var_list_max_until">31-dec-9999</Value>
                  <Value AttributeID="atr_pt_calc" Derived="true">name 1</Value>
               </Values>

            </Product>
            <Product ID="prd_15004" UserTypeID="obj_product" ParentID="prd_en_10005897">
               <Name>banana</Name>
               <ClassificationReference ClassificationID="cls_loy_bonus_current_5002_klm" Type="ref_loyalty_promotion"/>
               <ClassificationReference ClassificationID="cls_1_7361100" Type="ref_product_to_erpgroup"/>
               <AssetCrossReference AssetID="128178" Type="ref_primary_product_image"/>
               <Values>
                  <Value AttributeID="atr_ext_var_list_ed_010_KRL">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_010_KRL">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_ed_011_KRS">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_011_KRS">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_nr">15004</Value>
                  <Value AttributeID="atr_ext_var_list_ed_012_TVR">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_012_TVR">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_sd_013_ELS">2017-08-08</Value>
                  <Value AttributeID="atr_loy_current_promo_number">42010</Value>
                  <Value AttributeID="atr_ext_var_list_ed_013_ELS">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_014_PSK">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_sd_015_ODN">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_ed_014_PSK">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_002_KLM">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_sd_003_VLD">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_ed_002_KLM">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_ed_003_VLD">9999-12-31</Value>
                  <Value AttributeID="atr_ext_ar_nr">15</Value>
                  <Value AttributeID="atr_ext_var_list_ed_004_RYA">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_004_RYA">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_sd_005_YAR">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_sd_006_TUL">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_ed_005_YAR">9999-12-31</Value>
                  <Value AttributeID="atr_loy_current_promo_name">extra bonuses</Value>
                  <Value AttributeID="atr_loy_current_promo_end_date">2017-10-24</Value>
                  <Value AttributeID="atr_loy_current_promo_start_date">2017-10-11</Value>
                  <Value AttributeID="atr_ext_var_list_ed_006_TUL">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_ed_001_SCH">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_001_SCH">2017-08-08</Value>
                  <Value AttributeID="atr_ext_var_list_ed_015_ODN">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_max_until">31-dec-9999</Value>
                  <Value AttributeID="atr_pt_calc" Derived="true">name 2</Value>
               </Values>

            </Product>
            <Product ID="prd_1569001" UserTypeID="obj_product" ParentID="prd_en_10005921">
               <Name>name</Name>
               <ClassificationReference ClassificationID="cls_loy_bonus_current_5002_klm" Type="ref_loyalty_promotion"/>
               <ClassificationReference ClassificationID="cls_1_7361200" Type="ref_product_to_erpgroup"/>
               <ClassificationReference ClassificationID="cls_1_7361700" Type="ref_product_to_erpgroup"/>
               <AssetCrossReference AssetID="161621" Type="ref_primary_product_image"/>
               <AssetCrossReference AssetID="188035" Type="ref_secondary_image"/>
               <Values>
                  <Value AttributeID="atr_ext_var_list_ed_010_KRL">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_010_KRL">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_ed_011_KRS">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_011_KRS">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_nr">1569001</Value>
                  <Value AttributeID="atr_ext_var_list_ed_012_TVR">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_012_TVR">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_sd_013_ELS">2017-04-05</Value>
                  <Value AttributeID="atr_loy_current_promo_number">42010</Value>
                  <Value AttributeID="atr_ext_var_list_ed_013_ELS">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_014_PSK">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_sd_015_ODN">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_ed_014_PSK">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_002_KLM">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_sd_003_VLD">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_ed_002_KLM">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_ed_003_VLD">9999-12-31</Value>
                  <Value AttributeID="atr_ext_ar_nr">1569</Value>
                  <Value AttributeID="atr_ext_var_list_ed_004_RYA">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_004_RYA">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_sd_005_YAR">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_sd_006_TUL">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_ed_005_YAR">9999-12-31</Value>
                  <Value AttributeID="atr_loy_current_promo_name">extra bonuses</Value>
                  <Value AttributeID="atr_loy_current_promo_end_date">2017-10-24</Value>
                  <Value AttributeID="atr_loy_current_promo_start_date">2017-10-11</Value>
                  <Value AttributeID="atr_ext_var_list_ed_006_TUL">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_ed_001_SCH">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_sd_001_SCH">2017-04-05</Value>
                  <Value AttributeID="atr_ext_var_list_ed_015_ODN">9999-12-31</Value>
                  <Value AttributeID="atr_ext_var_list_max_until">31-dec-9999</Value>
                  <Value AttributeID="atr_pt_calc" Derived="true">name 3</Value>
               </Values>

            </Product>
         </Products>
      </STEP-ProductInformation>
   </ns0:Message1>
</ns0:Messages>

और आउटपुट है

    <?xml version="1.0" encoding="UTF-8"?>
<Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
   <Message1>
      <Id>SAP_ERP_MATNR</Id>
      <Timestamp/>
      <UserName/>
      <SourceSystemId/>
      <Products>
         <IdOrigin>SAP_ERP_MATNR</IdOrigin>
         <Id>388061</Id>
         <Name>name 1</Name>
         <Description>name 1</Description>
      </Products>
      <Products>
         <IdOrigin>SAP_ERP_MATNR</IdOrigin>
         <Id>388061</Id>
         <Name>name 1</Name>
         <Description>name 1</Description>
      </Products>
      <Products>
         <IdOrigin>SAP_ERP_MATNR</IdOrigin>
         <Id>388061</Id>
         <Name>name 1</Name>
         <Description>name 1</Description>
      </Products>
   </Message1>
   <Message2/>
   <Message3/>
</Messages>

एक्सएसएल परिवर्तन के बाद

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:StringBuffer="java.lang.StringBuffer" xmlns:date="http://exslt.org/dates-and-times" xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge"  exclude-result-prefixes="java date StringBuffer" version="1.0">

    <xsl:output method="xml" indent="yes"/>
      <xsl:template match="node()|@*">
      <xsl:variable name="valueFromSource" select=".//Product"/>
<Messages>
    <Message1>
    <Id>SAP_ERP_MATNR</Id>
    <Timestamp></Timestamp>
    <UserName></UserName>
    <SourceSystemId></SourceSystemId>
    <xsl:for-each select="$valueFromSource">
    <Products>
        <IdOrigin>SAP_ERP_MATNR</IdOrigin>
        <Id><xsl:value-of select="..//Value[@AttributeID='atr_ext_ar_nr']"/></Id>
        <Name><xsl:value-of select="/ns0:Messages/ns0:Message1/STEP-ProductInformation/Products/Product/Values/Value[@AttributeID='atr_pt_calc']"/></Name>
        <Description><xsl:value-of select="/ns0:Messages/ns0:Message1/STEP-ProductInformation/Products/Product/Values/Value[@AttributeID='atr_pt_calc']"/></Description>
    </Products>
    </xsl:for-each>
    </Message1>
    <Message2>

    </Message2>
    <Message3>

    </Message3>
</Messages>
    </xsl:template>
</xsl:stylesheet>

लेकिन मैं वह आउटपुट प्राप्त करना चाहता हूं

<?xml version="1.0" encoding="UTF-8"?>
<Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
   <Message1>
      <Id>SAP_ERP_MATNR</Id>
      <Timestamp/>
      <UserName/>
      <SourceSystemId/>
      <Products>
         <IdOrigin>SAP_ERP_MATNR</IdOrigin>
         <Id>388061</Id>
         <Name>name 1</Name>
         <Description>name 1</Description>
      </Products>
      <Products>
         <IdOrigin>SAP_ERP_MATNR</IdOrigin>
         <Id>15</Id>
         <Name>name 2</Name>
         <Description>name 2</Description>
      </Products>
      <Products>
         <IdOrigin>SAP_ERP_MATNR</IdOrigin>
         <Id>1569</Id>
         <Name>name 3</Name>
         <Description>name 3</Description>
      </Products>
   </Message1>
   <Message2/>
   <Message3/>
</Messages>

नाम 2 के बजाय नाम 1, नाम 3 के बजाय नाम 1. 15 के बजाय 388061, 1569 के बजाय 388061।

सही परिणाम पाने के लिए मुझे अपने एक्सएसएल में क्या बदलाव करने चाहिए? अग्रिम में धन्यवाद।

0
Vladimir Mikhailov 9 नवम्बर 2017, 19:05

1 उत्तर

सबसे बढ़िया उत्तर

xsl:value-of में आपके दो भाव /ns0:Messages/ से शुरू होते हैं, जिसका अर्थ है कि वे दस्तावेज़ नोड से चयन करना शुरू कर देंगे, जो दस्तावेज़ में पाए जाने वाले पहले मान का चयन करेगा, चाहे आप कहीं भी हों।

इसमें xsl:for-each बदलें, जिसमें वर्तमान Product नोड के सापेक्ष भाव हैं।

<xsl:for-each select="$valueFromSource">
    <Products>
        <IdOrigin>SAP_ERP_MATNR</IdOrigin>
        <Id><xsl:value-of select="Values/Value[@AttributeID='atr_ext_ar_nr']"/></Id>
        <Name><xsl:value-of select="Values/Value[@AttributeID='atr_pt_calc']"/></Name>
        <Description><xsl:value-of select="Values/Value[@AttributeID='atr_pt_calc']"/></Description>
    </Products>
</xsl:for-each>
0
Tim C 9 नवम्बर 2017, 20:11