我有以下XML:XSL每個元素的屬性值獲取元素值
<?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_renewable_goods_quantity」設置爲0
我的XSL轉換(無規則 'atr_ext_var_list_max_until' < =當前日期):
<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 i之後得到:
<?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>
對於調試我使用<comment>
和結果的第二上下文獲取是來自源的第一上下文值。 誰知道我必須改變我的XSL轉換來獲得正確的環境價值觀:在第一源<Value AttributeID="atr_ext_var_list_max_until">2017-09-08</Value>
的 到第一個結果<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>
,不值從源2017年9月8日 的第一方面? 謝謝!
謝謝!它工作正常。但是現在不能調用java函數來反轉字符串。我聲明''並調用此函數' ',但得到錯誤」無法找到外部方法'new'(必須公開)「如何正確調用'reverse'? –
如果這個答案適用於你原來的問題,請接受它。對於你的新問題,我認爲調用StringBuffer的格式應該更像StringBuffer:reverse(StringBuffer:new($ con)),但我沒有測試過它。我會建議提出一個新問題,以便確定知道的人可以提供幫助。 – EdmCoff