2017-09-08 3 views
0

ich folgende XML haben:XSL für jedes Element Elementwert von Attributwert erhalten

<?xml version="1.0" encoding="UTF-8"?> 
<STEP-ProductInformation ExportTime="2016-08-08 18:21:16" ExportContext="en-EN" ContextID="en-EN" WorkspaceID="Main" UseContextLocale="false"> 
<Classifications> 
... 
</Classifications> 
    <Products> 
     <Product ID="prd_119481004" UserTypeID="obj_product" ParentID="prd_eng_10000807"> 
     <Name>product name1</Name> 
     <ClassificationReference ClassificationID="cls_0121781" Type="ref_etc_online_catalog"/> 
     <Values> 
      <Value AttributeID="atr_web_preoder_sell_type" ID="117184">23</Value> 
      <Value AttributeID="atr_self_checkout_weight">0.13</Value> 
      <Value AttributeID="atr_picking_weight_deviation">10</Value> 
      <Value AttributeID="atr_renewable_goods_quantity">1000</Value> 
      <Value AttributeID="atr_ext_var_gtin">atr_renewable_goods_quantity</Value> 
      <Value AttributeID="atr_ext_bas_volume">90</Value> 
      <Value AttributeID="atr_ext_var_uom_bas">ST</Value> 
      <Value AttributeID="atr_space_planning_height">9,5</Value> 
      <Value AttributeID="atr_space_planning_width">6</Value> 
      <Value AttributeID="atr_ext_ar_gr_nr_1">6454100</Value> 
      <MultiValue AttributeID="atr_ru_storage_temperature1"> 
       <Value>25</Value> 
      </MultiValue> 
      <Value AttributeID="atr_space_planning_depth">3</Value> 
      <Value AttributeID="atr_ext_var_list_max_until">2017-09-08</Value> 
      <Value AttributeID="atr_ru_vat" Derived="true">18</Value> 
      <Value AttributeID="atr_pt_calc" Derived="true">fgsdg</Value> 
      <Value AttributeID="atr_ru_shelf_life_val_uom" Derived="true">3</Value> 
      <Value AttributeID="atr_shelf_num" Derived="true">3</Value> 
      <Value AttributeID="atr_storage_num" Derived="false">280035555</Value> 
      <Value AttributeID="atr_ru_bas_volume" Derived="true">0.09</Value> 
      <Value AttributeID="atr_bypass_order" Derived="true">1017</Value> 
      <Value AttributeID="atr_ru_shelflife_temperature1_formula" Derived="true">25°C</Value> 
      <Value AttributeID="atr_picking_zone" Derived="true">1017</Value> 
     </Values> 
     </Product> 
     <Product ID="prd_119478004" UserTypeID="obj_product" ParentID="prd_eng_10000807"> 
     <Name>product name2</Name> 
     <ClassificationReference ClassificationID="cls_0121781" Type="ref_etc_online_catalog"/> 
     <Values> 
      <Value AttributeID="atr_web_preoder_sell_type" ID="117184">123</Value> 
      <Value AttributeID="atr_self_checkout_weight">0.14</Value> 
      <Value AttributeID="atr_picking_weight_deviation">10</Value> 
      <Value AttributeID="atr_ext_var_gtin">4607177761992</Value> 
      <Value AttributeID="atr_ext_bas_volume">90</Value> 
      <Value AttributeID="atr_ext_var_uom_bas">ST</Value> 
      <Value AttributeID="atr_space_planning_height">9,5</Value> 
      <Value AttributeID="atr_space_planning_width">6</Value> 
      <Value AttributeID="atr_ext_ar_gr_nr_1">6454100</Value> 
      <MultiValue AttributeID="atr_ru_storage_temperature1"> 
       <Value>+25</Value> 
      </MultiValue> 
      <Value AttributeID="atr_space_planning_depth">3</Value> 
      <Value AttributeID="atr_ext_var_list_max_until">2015-12-31</Value> 
      <Value AttributeID="atr_ru_vat" Derived="true">18</Value> 
      <Value AttributeID="atr_pt_calc" Derived="true">dgheyareatgraehgh</Value> 
      <Value AttributeID="atr_ru_shelf_life_val_uom" Derived="true">3</Value> 
      <Value AttributeID="atr_shelf_num" Derived="true">3</Value> 
      <Value AttributeID="atr_storage_num" Derived="true">28003</Value> 
      <Value AttributeID="atr_ru_bas_volume" Derived="true">0.09</Value> 
      <Value AttributeID="atr_bypass_order" Derived="true">1017</Value> 
      <Value AttributeID="atr_ru_shelflife_temperature1_formula" Derived="true">25 °C</Value> 
      <Value AttributeID="atr_picking_zone" Derived="true">1017</Value> 
     </Values> 
     </Product> 
    </Products> 
</STEP-ProductInformation> 

und Regel Wenn Datum in Attribut 'atr_ext_var_list_max_until' < = aktuelle Datum als:

  • 'atr_storage_num' muss leer sein

  • 'atr_shelf_num' muss leer sein

  • ‚atr_renewable_goods_quantity‘ auf 0

Meine XSL-Transformation (ohne Regel 'atr_ext_var_list_max_until' < = aktuelles Datum):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java" version="1.0"> 

    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="node()|@*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 


    <xsl:variable name="currdate" select="java:format(java:java.text.SimpleDateFormat.new('yyyy-MM-dd'), java:java.util.Date.new())" /> 
    <xsl:variable name="date" select="/STEP-ProductInformation/Products/Product/Values/Value[@AttributeID = 'atr_ext_var_list_max_until']" /> 
    <xsl:variable name="bool" select="$date = $currdate" /> 


    <xsl:template match="node()[@AttributeID = 'atr_storage_num']"> 
      <xsl:variable name="vAttribs" select="@AttributeID | @Derived"/> 
      <xsl:variable name="date" select="/STEP-ProductInformation/Products/Product/Values/Value[@AttributeID = 'atr_ext_var_list_max_until']" /> 
      <Value><xsl:copy-of select="$vAttribs"/><xsl:text>CONST1</xsl:text><xsl:comment><xsl:value-of select="$date" /></xsl:comment></Value> 
    </xsl:template> 


    <xsl:template match="node()[@AttributeID = 'atr_shelf_num']">  
      <xsl:variable name="vAttribs" select="@AttributeID | @Derived"/> 
      <Value><xsl:copy-of select="$vAttribs"/><xsl:text>CONST2</xsl:text></Value>  
    </xsl:template> 

    <xsl:template match="node()[@AttributeID = 'atr_renewable_goods_quantity']"> 
      <xsl:variable name="vAttribs" select="@AttributeID | @Derived"/> 
      <Value><xsl:copy-of select="$vAttribs"/><xsl:text>CONST3</xsl:text></Value>   
    </xsl:template> 

</xsl:stylesheet> 

<!-- <xsl:comment><xsl:value-of select="$bool" /></xsl:comment> --> 

funktioniert nicht. dieses XSL Nach der Verwendung von i erhalten:

<?xml version="1.0" encoding="UTF-8"?> 
<STEP-ProductInformation ExportTime="2016-08-08 18:21:16" ExportContext="en-EN" ContextID="en-EN" WorkspaceID="Main" UseContextLocale="false"> 
    <Classifications> 
    ... 
    </Classifications> 
     <Products> 
      <Product ID="prd_119481004" UserTypeID="obj_product" ParentID="prd_eng_10000807"> 
      <Name>product name1</Name> 
      ... 
       <Value AttributeID="atr_renewable_goods_quantity">CONST3</Value> 
       <Value AttributeID="atr_ext_var_list_max_until">2017-09-08</Value>    
       <Value AttributeID="atr_shelf_num" Derived="true">CONST2</Value> 
       <Value AttributeID="atr_storage_num" Derived="false">CONST1<!--2017-09-08--></Value> 
      ... 
      </Values> 
      </Product> 
      <Product ID="prd_119478004" UserTypeID="obj_product" ParentID="prd_eng_10000807"> 
      <Name>product name2</Name>    
      ... 
       <Value AttributeID="atr_ext_var_list_max_until">2015-12-31</Value>    
       <Value AttributeID="atr_shelf_num" Derived="true">CONST2</Value> 
       <Value AttributeID="atr_storage_num" Derived="true">CONST1<!--2017-09-08--></Value> 
      ... 
      </Values> 
      </Product> 
     </Products> 
    </STEP-ProductInformation> 

Für i Debuggen <comment> verwenden und im zweiten Kontext des Ergebnisses ist Wert aus dem ersten Kontext der Quelle erhalten. Wer weiß, wie ich muß meine XSL-Transformation ändern Werte richtigen Kontext zu erhalten: in erster Quelle <Value AttributeID="atr_ext_var_list_max_until">2017-09-08</Value> zur ersten Ergebnis <Value AttributeID="atr_storage_num" Derived="false">CONST1<!--2017-09-08--></Value> und <Value AttributeID="atr_ext_var_list_max_until">2015-12-31</Value>-<Value AttributeID="atr_storage_num" Derived="true">CONST1<!--2015-12-31--></Value>, nicht Wert aus dem ersten Kontext der Quelle 2017.09.08 ? Danke!

Antwort

0

Unter der Annahme, verstehe ich Ihre Frage richtig und Sie sind einfach besorgt über die CONST1 Datum, müssen Sie

<xsl:variable name="date" select="/STEP-ProductInformation/Products/Product/Values/Value[@AttributeID = 'atr_ext_var_list_max_until']" /> 

zu

<xsl:variable name="date" select="../Value[@AttributeID = 'atr_ext_var_list_max_until']" /> 

Ihre aktuellen XSL für einen Knoten wird sich ändern aus der Stamm, der diesem Pfad entspricht. Das ".." bedeutet, dass Sie von dem übergeordneten Knoten des aktuellen Knotens suchen.

+0

Vielen Dank! Es funktioniert gut. Aber jetzt kann Java-Funktion nicht aufrufen, um die Zeichenfolge umzukehren. Ich deklariere ' 'und Aufruf dieser Funktion' ', aber Fehler erhalten "Externe Methode kann nicht gefunden werden" neu "(muss öffentlich sein)" Wie wird 'reverse' korrekt aufgerufen? –

+0

Wenn diese Antwort für Ihre ursprüngliche Frage funktioniert hat, akzeptieren Sie sie bitte. Für Ihre neue Frage, ich denke, das Format für den Aufruf von StringBuffer sollte mehr wie StringBuffer: Reverse (StringBuffer: new ($ con)), aber ich habe es nicht getestet. Ich würde empfehlen, eine neue Frage zu stellen, damit jemand, der sicher weiß, helfen kann. – EdmCoff