我确定这真的很容易,但是我的脑袋一下子就开始了。 我试图通过使用Muenchian方法在XSL中实现Group By。然而,我读过的所有示例都看起来都在2个节点上,我需要多个节点。所以我试过修改代码但是现在失败了...... 我的XML是: -
search
我需要格式
<?xml version="1.0" encoding="UTF-8" ?>
<KBBCONNECTJOB>
<OGOODS>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>Base End Support Panel Natural Oak</NAME>
<POS>1</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>600MM Highline Integrated Dishwasher Fascia</NAME>
<POS>2</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>600MM Highline Base Unit</NAME>
<POS>3</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>600MM Highline Integrated Fridge/Freeezer Fascia</NAME>
<POS>4</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>600MM 3 Drawer Pan Unit</NAME>
<POS>5</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>600MM Highline Base Unit</NAME>
<POS>6</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>500MM Highline Base Unit</NAME>
<POS>7</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>600MM Fridge/Freezer Housing Unit - Type 6</NAME>
<POS>8</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>600MM Double Oven Housing Unit - Type 2</NAME>
<POS>9</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>2650 Plinth Natural Oak Inc Seal Strip</NAME>
<POS>10</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>Worktop 600 Single P/F 4000 Black Brazil</NAME>
<POS>11</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>30MM Bullnose Sq Cornice 3600MM Natural</NAME>
<POS>12</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>10Mtr Roll Edging Tape Natural Oak</NAME>
<POS>13</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<CODE>ET03</CODE>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>Schock Stnd Inset 1.5 Bowl Drainer Sink</NAME>
<POS>14</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>90</SUPP>
<WHAT>1</WHAT>
<NAME>Schock Universal Plumbing Kit 1.5 Bowl</NAME>
<POS>15</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>130</SUPP>
<WHAT>3</WHAT>
<NAME>CDA - Integrated Combination Fridge/freezer 70/30 A+ Rated</NAME>
<POS>1</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>130</SUPP>
<WHAT>3</WHAT>
<NAME>CDA - Integrated Washing Machine</NAME>
<POS>2</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>130</SUPP>
<WHAT>3</WHAT>
<NAME>CDA - Double Oven Bi Aa Rated Main Oven Touch Control Clock S/steel</NAME>
<POS>3</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>130</SUPP>
<WHAT>3</WHAT>
<NAME>CDA - Five Burner Front Control 70cm Gas Hob Wok Ffd Stainless Steel</NAME>
<POS>4</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>130</SUPP>
<WHAT>3</WHAT>
<NAME>CDA - 70cm Chimney Extractor Hood - Stainless Steel</NAME>
<POS>5</POS>
<ORDERNO>2204</ORDERNO>
</Row>
<Row>
<SUPP>130</SUPP>
<WHAT>3</WHAT>
<NAME>CDA - Fully Integrated Dishwasher 60 Cm A++Aa Rated</NAME>
<POS>6</POS>
<ORDERNO>2204</ORDERNO>
</Row>
</OGOODS>
</KBBCONNECTJOB>
订单号始终相同,但其他部分可能全部相同,或者全部来自同一SUPP,或者每行可能不同。
我现在的部分工作的XSL是: -
order
what
supp
name what pos ordercat
<?xml version="1.0" encoding="utf-16"?>
<order display="2204">
<productgroup display="Kitchen Units">
<supplier display="supplier 1 from lookup">
<product display="Base End Support Panel Natural Oak" what="1"pos= "1" ordercat="D" />
<product display="600MM Highline Integrated Dishwasher Fascia" what="1"pos= "2" ordercat="D" />
<product display="600MM Highline Base Unit" what="1"pos= "3" ordercat="D" />
<product display="600MM Highline Integrated Fridge/Freeezer Fascia" what="1"pos= "4" ordercat="D" />
<product display="600MM 3 Drawer Pan Unit" what="1"pos= "5" ordercat="D" />
<product display="600MM Highline Base Unit" what="1"pos= "6" ordercat="D" />
<product display="500MM Highline Base Unit" what="1"pos= "7" ordercat="D" />
<product display="600MM Fridge/Freezer Housing Unit - Type 6" what="1"pos= "8" ordercat="D" />
<product display="600MM Double Oven Housing Unit - Type 2" what="1"pos= "9" ordercat="D" />
<product display="2650 Plinth Natural Oak Inc Seal Strip" what="1"pos= "10" ordercat="D" />
<product display="Worktop 600 Single P/F 4000 Black Brazil" what="1"pos= "11" ordercat="D" />
<product display="30MM Bullnose Sq Cornice 3600MM Natural" what="1"pos= "12" ordercat="D" />
<product display="10Mtr Roll Edging Tape Natural Oak" what="1"pos= "13" ordercat="D" />
<product display="Schock Stnd Inset 1.5 Bowl Drainer Sink" what="1"pos= "14" ordercat="D" />
<product display="Schock Universal Plumbing Kit 1.5 Bowl" what="1"pos= "15" ordercat="D" />
</supplier>
</productgroup>
<productgroup display="Appliances">
<supplier display="Supplier 2 from lookup">
<product display="CDA - Integrated Combination Fridge/freezer 70/30 A+ Rated" what="3"pos= "1" ordercat="D" />
<product display="CDA - Integrated Washing Machine" what="3"pos= "2" ordercat="D" />
<product display="CDA - Double Oven Bi Aa Rated Main Oven Touch Control Clock S/steel" what="3"pos= "3" ordercat="D" />
<product display="CDA - Five Burner Front Control 70cm Gas Hob Wok Ffd Stainless Steel" what="3"pos= "4" ordercat="D" />
<product display="CDA - 70cm Chimney Extractor Hood - Stainless Steel" what="3"pos= "5" ordercat="D" />
<product display="CDA - Fully Integrated Dishwasher 60 Cm A++Aa Rated" what="3"pos= "6" ordercat="D" />
</supplier>
</productgroup>
</order>
但它并没有为产品展示部分提供多行。我已经重新设计了一个可以从另一个文件中查找的部分,这个部分正在生产中。
如果有更简单的方法,我很乐意改变方法...... 提前谢谢。
答案 0 :(得分:0)
像你这样的锁很近
您的第一个for-each组按ORDERNO
排。
你的第二个for-each应该只考虑第一个已经为每个人选择的行。
因此,将您当前的ORDERNO
放入变量中。并在第二个for-each中使用levle0键。
<xsl:variable name="onr" select="ORDERNO" />
<xsl:for-each select="key('level0', $onr)[count(. | key('level1', concat($onr, '|', WHAT))[1]) = 1]"> <!-- get the WHAT groups -->
<xsl:sort select="WHAT" />
对于更深层的循环,请遵循此概念 注意:这是一个xslt 1.0 Muenchian分组解决方案。但你的样式表说2.0。因此还有其他可能性。