我希望通过连接fsxml/formula/ingrrow where itemcode = fsxml/item (attribute objkey)并将item中名为erpplantnr_11到erpplantnr_30的元素移动到每个ingrrow的最后一个attribute10元素之后,对以下XML进行排序。
提前感谢您能提供的任何帮助!
(简化并提供第一次XSLT尝试)(简化的示例-希望将erpplantnr_11元素移动到属性objkey与itemcode元素匹配的attribute1元素之后)
寻找有关如何创建“连接”的帮助。再次感谢。
(XSLT):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:fsxml="http://www.FormationSystems.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="formula">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="ingrrow"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ingrrow | item">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="itemcode"/>
<xsl:apply-templates select="attribute1"/>
<xsl:apply-templates select="erpplantnr_11"/>
</xsl:copy>
</xsl:template>
<xsl:template match="fsxml/fsxml">
<xsl:apply-templates select="item"/>
</xsl:template>
</xsl:stylesheet>结果XML -需要将两个item objectkey属性与它们的ingrrow itemcode匹配,并让输出xml在attribute1元素之后列出erpplantnr_11元素:
<fsxml>
<formula maxcol="51" keycount="2" fmt="A" dtlcodes="HEADER\INGR" objectkey="NOR000133\0002" filteredfields="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ingrrow detail="1" fmt="X">
<itemcode>NOR60506</itemcode>
<attribute1>000000000050051116</attribute1>
</ingrrow>
<ingrrow detail="1" fmt="X">
<itemcode>7K015</itemcode>
<attribute1>000000000000800479</attribute1>
</ingrrow>
</formula>
<item maxcol="35" keycount="1" fmt="A" dtlcodes="HEADER" objectkey="NOR60506" filteredfields="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<erpplantnr_11>121212;343434</erpplantnr_11>
</item>
<item maxcol="35" keycount="1" fmt="A" dtlcodes="HEADER" objectkey="7K015" filteredfields="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<erpplantnr_11>123456</erpplantnr_11>
</item>
</fsxml>原始XML:
<fsxml>
<formula maxcol="51" keycount="2" fmt="A" dtlcodes="HEADER\INGR" objectkey="NOR000133\0002" filteredfields="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<keycode>NOR000133</keycode>
<keycode2>0002</keycode2>
<description>48782 ALABASTER WHITE MB9960 NA</description>
<formulaalias />
<alternateformula />
<timedate xsi:nil="true" />
<productcode />
<productdescr />
<reportcode />
<reportregion />
<alias_code1 />
<alias_code2 />
<alias_code3 />
<alias_code4 />
<alias_code5 />
<alias_code6 />
<alias_code7 />
<alias_code8 />
<hseapacdoc />
<hseemeadoc />
<hsenasadoc />
<wau_local_designee />
<apac1_local_designee />
<apac2_local_designee />
<apc_local_designee />
<emea_local_designee />
<na_local_designee>PREST</na_local_designee>
<sa_local_designee />
<ras_sent>Yes</ras_sent>
<erp_waunr />
<erp_apac1nr />
<erp_apac2nr />
<erp_apcnr />
<erp_emeanr />
<erp_nornr />
<erp_sanr />
<crfc_code>NOR000133</crfc_code>
<orig_desc />
<erpglobal_1 />
<erpglobal_2 />
<erpglobal_3 />
<uomcode>KG</uomcode>
<itemcode>NOR000133</itemcode>
<yield>74.8956541853986</yield>
<yieldpct>100</yieldpct>
<phantomind>0</phantomind>
<primaryformulaind>1</primaryformulaind>
<processyield>100</processyield>
<projectcode />
<labbookcode />
<labbookpage />
<ownercode>ARFTL</ownercode>
<groupcode>GROUP_1</groupcode>
<statusind>291</statusind>
<approvalcode />
<holdcode />
<workcode />
<workcode2 />
<formulatorcode>ARFTL</formulatorcode>
<yieldcalcind>1</yieldcalcind>
<customer>RO_NOR</customer>
<comment />
<datemodified>2012-05-11T14:55:37</datemodified>
<class>PRODUCT</class>
<typeind>0</typeind>
<parentfid>42871</parentfid>
<mfgitemmaster>NOR000133\0002</mfgitemmaster>
<calcmode>0</calcmode>
<formulaid>728067</formulaid>
<adjustparam />
<materialchange>1</materialchange>
<judgement />
- <ingrrow detail="1" fmt="X">
<lineid>1</lineid>
<itemcode>NOR60506</itemcode>
<quantity>66.6877872652848</quantity>
<uomcode>KG</uomcode>
<description>KV1348 KV1348 White Dispersion</description>
<materialpct>89.0409303324918</materialpct>
<linebreakcode />
<scaleind>0</scaleind>
<subformulaind>0</subformulaind>
<formulaid>0</formulaid>
<componentind>1</componentind>
<instruction />
<substituteind>0</substituteind>
<formulacode>NOR60506\0006</formulacode>
<status>401</status>
<class />
<decdigit>0</decdigit>
<cas />
<commcode />
<aliascode1 />
<aliascode2 />
<aliascode3 />
<aliascode4 />
<activequantity>0</activequantity>
<relqtypct>0</relqtypct>
<attribute1>000000000050051116</attribute1>
<attribute2 />
<attribute3 />
<attribute4 />
<attribute5 />
<instrucflag>1</instrucflag>
<paramcode />
<pvalue xsi:nil="true" />
<lotcode />
<aliascode5 />
<aliascode6 />
<aliascode7>APC 56% 5T070/3Z145 (KV1348) / P:393367</aliascode7>
<aliascode8 />
<sectionname />
<sectiontype>0</sectiontype>
<adjustind>0</adjustind>
<attribute6 />
<attribute7 />
<attribute8 />
<attribute9 />
<attribute10 />
</ingrrow>
- <ingrrow detail="1" fmt="X">
<lineid>2</lineid>
<itemcode>7K015</itemcode>
<quantity>8.20786692011385</quantity>
<uomcode>KG</uomcode>
<description>METHYLAMYLKETONE</description>
<materialpct>10.9590696675082</materialpct>
<linebreakcode />
<scaleind>0</scaleind>
<subformulaind>0</subformulaind>
<formulaid>0</formulaid>
<componentind>8</componentind>
<instruction />
<substituteind>0</substituteind>
<status>401</status>
<class />
<decdigit>0</decdigit>
<cas>110-43-0</cas>
<commcode />
<aliascode1>S194</aliascode1>
<aliascode2>METHYL AMYL KETONE</aliascode2>
<aliascode3 />
<aliascode4>METHYLAMYLKETONE</aliascode4>
<activequantity>0</activequantity>
<relqtypct>0</relqtypct>
<attribute1>000000000000800479</attribute1>
<attribute2 />
<attribute3 />
<attribute4 />
<attribute5 />
<instrucflag>1</instrucflag>
<paramcode />
<pvalue xsi:nil="true" />
<lotcode />
<aliascode5>METHYLAMYLKETONE</aliascode5>
<aliascode6>Methylamylketon 165,5 KG</aliascode6>
<aliascode7>METHYL N-AMYL KETONE (Bulk)</aliascode7>
<aliascode8 />
<sectionname />
<sectiontype>0</sectiontype>
<adjustind>0</adjustind>
<attribute6 />
<attribute7 />
<attribute8 />
<attribute9 />
<attribute10 />
</ingrrow>
</formula>
- <fsxml>
- <item maxcol="35" keycount="1" fmt="A" dtlcodes="HEADER" objectkey="NOR60506" filteredfields="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<keycode>NOR60506</keycode>
<description>KV1348 White Dispersion</description>
<rmremark />
<ras_sent />
<erp_waunr />
<erp_apac1nr />
<erp_apac2nr />
<erp_apcnr />
<erp_emeanr />
<erp_nornr>000000000050051116</erp_nornr>
<erp_sanr />
<erpglobal_1 />
<erpglobal_2 />
<erpglobal_3 />
<erpplantnr_11>121212;343434</erpplantnr_11>
<erpplantnr_12 />
<erpplantnr_13 />
<erpplantnr_14 />
<erpplantnr_15 />
<erpplantnr_16 />
<erpplantnr_17 />
<erpplantnr_18 />
<erpplantnr_19 />
<erpplantnr_20 />
<erpplantnr_21 />
<erpplantnr_22 />
<erpplantnr_23 />
<erpplantnr_24 />
<erpplantnr_25 />
<erpplantnr_26 />
<erpplantnr_27 />
<erpplantnr_28 />
<erpplantnr_29 />
<erpplantnr_30 />
<uomcode>KG</uomcode>
<calcind>0</calcind>
<scaleind>0</scaleind>
<statusind>401</statusind>
<approvalcode />
<class />
<componentind>1</componentind>
<linebreakcode />
<holdcode />
<formulacode>NOR60506</formulacode>
<version>0006</version>
<cas />
<commcode />
<aliascode1 />
<aliascode2 />
<aliascode3 />
<aliascode4 />
<aliascode5 />
<aliascode6 />
<aliascode7>APC 56% 5T070/3Z145 (KV1348) / P:393367</aliascode7>
<aliascode8 />
<threshold>0</threshold>
<datemodified>2012-04-28T19:50:12</datemodified>
<ftypeind>0</ftypeind>
<judgement />
</item>
- <item maxcol="35" keycount="1" fmt="A" dtlcodes="HEADER" objectkey="7K015" filteredfields="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<keycode>7K015</keycode>
<description>METHYLAMYLKETONE</description>
<rmremark />
<ras_sent />
<erp_waunr>S194</erp_waunr>
<erp_apac1nr>00000000000007K015</erp_apac1nr>
<erp_apac2nr />
<erp_apcnr>7K015</erp_apcnr>
<erp_emeanr>000000000000800479</erp_emeanr>
<erp_nornr>000000000000800479</erp_nornr>
<erp_sanr />
<erpglobal_1 />
<erpglobal_2 />
<erpglobal_3 />
<erpplantnr_11>123456</erpplantnr_11>
<erpplantnr_12>234567</erpplantnr_12>
<erpplantnr_13>345678</erpplantnr_13>
<erpplantnr_14>456789</erpplantnr_14>
<erpplantnr_15>567890</erpplantnr_15>
<erpplantnr_16>678901</erpplantnr_16>
<erpplantnr_17>789012</erpplantnr_17>
<erpplantnr_18>890123</erpplantnr_18>
<erpplantnr_19>901234</erpplantnr_19>
<erpplantnr_20>012345</erpplantnr_20>
<erpplantnr_21>654321</erpplantnr_21>
<erpplantnr_22>765432</erpplantnr_22>
<erpplantnr_23>876543</erpplantnr_23>
<erpplantnr_24>987654</erpplantnr_24>
<erpplantnr_25>098765</erpplantnr_25>
<erpplantnr_26>109876</erpplantnr_26>
<erpplantnr_27>210987</erpplantnr_27>
<erpplantnr_28>321098</erpplantnr_28>
<erpplantnr_29>432109</erpplantnr_29>
<erpplantnr_30>543210</erpplantnr_30>
<uomcode>KG</uomcode>
<calcind>0</calcind>
<scaleind>0</scaleind>
<statusind>401</statusind>
<approvalcode />
<class />
<componentind>8</componentind>
<linebreakcode />
<holdcode />
<formulacode />
<version />
<cas>110-43-0</cas>
<commcode />
<aliascode1>S194</aliascode1>
<aliascode2>METHYL AMYL KETONE</aliascode2>
<aliascode3 />
<aliascode4>METHYLAMYLKETONE</aliascode4>
<aliascode5>METHYLAMYLKETONE</aliascode5>
<aliascode6>Methylamylketon 165,5 KG</aliascode6>
<aliascode7>METHYL N-AMYL KETONE (Bulk)</aliascode7>
<aliascode8 />
<threshold>0</threshold>
<datemodified>2012-04-24T22:52:56</datemodified>
<ftypeind>0</ftypeind>
<judgement />
</item>
</fsxml>
</fsxml>发布于 2012-05-14 21:40:02
我仍然很难理解你到底需要什么,但我希望这能帮助你开始工作。
我假设您想要复制输入XML,但是您不想复制item和ingrrow,而是希望从相应的item中取出这些erpplantnr_元素,并将它们放在ingrrow的最后一个attribute子节点之后。
虽然我们可以在XPath谓词中进行内联查找,但最好将xsl:key and fn:key()看作是表示查找的更好方法:
<xsl:key name="items" match="/fsxml/fsxml/item" use="@objectkey"/>这将通过@objectkey来“索引”所有的item。接下来,让我们把身份变换放进去,就像你做的那样:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>接下来,我们让item静默,因为我们已经说过,我们只需要取出一些匹配的item来显示在其他地方:
<xsl:template match="item"/>最后,让我们截取最后一个attribute节点,并在它之后注入匹配的erpplantnr_节点:
<xsl:template match="ingrrow/*[contains(local-name(), 'attribute')][last()]">
<xsl:copy-of select="."/>
<xsl:apply-templates select="key('items', current()/parent::*/itemcode)/*[contains(local-name(), 'erpplantnr_')]"/>
</xsl:template>在这里,我们复制最后一个attribute节点,然后使用该键查找匹配的item节点,从该节点中,我们按照所有erpplantnr_在文档中出现的顺序枚举它们。
我不确定您希望这些选择器有多通用或多具体,所以我选择了一个中间位置。
当我在您的输入文档上运行这个转换时,我得到了它的一个副本,没有item节点,但是在每个erpplantnr_中的attribute10节点后面复制了相应的ingrrow。
希望能有所帮助。
附注:完整的转换列表以防万一:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:fsxml="http://www.FormationSystems.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="items" match="/fsxml/fsxml/item" use="@objectkey"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="item"/>
<xsl:template match="ingrrow/*[contains(local-name(), 'attribute')][last()]">
<xsl:copy-of select="."/>
<xsl:apply-templates select="key('items', current()/parent::*/itemcode)/*[contains(local-name(), 'erpplantnr_')]"/>
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/10557841
复制相似问题