2017-09-08 3 views
0

속성 값으로 요소 값을 얻을 :XSL 내가 XML 다음 한

<?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> 

및 지배하면 < = 현재 날짜보다 'atr_ext_var_list_max_until'속성 날짜 :

  • 'atr_storage_num' 비어 있어야합니다.

  • 'atr_shelf_num'은 (는) 비워야합니다.

  • (< = 현재 날짜 'atr_ext_var_list_max_until'규칙없이) 0

내 XSL 변환으로 설정

  • 'atr_renewable_goods_quantity'

    <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> --> 
    

    이 작동하지 않습니다. XSL이 사용 후 내가 얻을 : 나 <comment>를 사용하여 결과의 ​​제 2의 문맥 드릴 디버깅에

    <?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> 
    

    소스의 제 컨텍스트 값이다. 에 대한 첫 번째 결과 <Value AttributeID="atr_storage_num" Derived="false">CONST1<!--2017-09-08--></Value><Value AttributeID="atr_ext_var_list_max_until">2015-12-31</Value><Value AttributeID="atr_storage_num" Derived="true">CONST1<!--2015-12-31--></Value>에 소스 <Value AttributeID="atr_ext_var_list_max_until">2017-09-08</Value>의 처음에 , 값이 아닌 소스 2017년 9월 8일 의 첫 문맥 : 누가 내가 잘 컨텍스트 값을 얻기 위해 내 XSL 변환을 변경해야합니다 방법을 알고? 감사합니다. 내가 제대로 질문을 이해하고있어 당신이 CONST1 날짜에 대해 간단하게 우려하고 있습니다 가정

  • 답변

    0

    , 당신은 변경해야

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

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

    현재 XSL은에서 노드를 찾습니다 그 패스와 일치하는 루트 ".."는 현재보고있는 노드의 부모로부터 검색을 시작하는 것을 의미합니다.

    +0

    감사합니다! 그것은 잘 작동합니다. 그러나 지금은 Java 함수를 호출하여 문자열을 역순으로 할 수 없습니다. 나는''이 함수를 호출하면 다음과 같은 결과가 나타납니다 : ', 그러나"외부 메소드 'new'(public이어야 함)를 찾을 수 없습니다. "'reverse'를 올바르게 호출하는 방법? –

    +0

    이 질문에 대한 답이 맞으면 동의하십시오. 귀하의 새 질문에 대해, 나는 StringBuffer를 호출하는 형식이 StringBuffer와 같아야한다고 생각한다 : reverse (StringBuffer : new ($ con)) 그러나 나는 그것을 테스트하지 않았다. 확실하게 알고있는 사람이 도울 수 있도록 새로운 질문을 제기하는 것이 좋습니다. – EdmCoff