Я работаю над группировкой, используя XSLT 1.0, но вывод не такой, как ожидалось.
Мне нужно суммировать количество в MovementLine для соответствующего Движения, но вместо этого сумма происходит для всего Движения вместо этого.Здесь ключ должен работать для каждого Движения, но не для всех
Исходный XML:
`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MovementFileFlowRequest>
<Movement>
<MovementLine>
<ArticleNumber>355</ArticleNumber>
<Quantity>10</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
<MovementLine>
<ArticleNumber>129</ArticleNumber>
<Quantity>10</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
<MovementLine>
<ArticleNumber>355</ArticleNumber>
<Quantity>50</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
</Movement>
<Movement>
<MovementLine>
<ArticleNumber>359</ArticleNumber>
<Quantity>10</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
</Movement>
<Movement>
<MovementLine>
<ArticleNumber>359</ArticleNumber>
<Quantity>10</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
</Movement>
</MovementFileFlowRequest>`
XSLT:
`<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes"/>
<xsl:key name="Movements" match="MovementLine" use="concat(ArticleNumber, '|', LogisticVariety, '|' , Status)"/>
<xsl:template match="/">
<xsl:for-each select="MovementFileFlowRequest">
<MovementFileFlowRequest >
<xsl:for-each select="Movement">
<!-- Apply "group" template to the first Record Line in group -->
<Movement>
<xsl:for-each select="MovementLine[generate-id() = generate-id(key('Movements', concat(ArticleNumber, '|', LogisticVariety, '|' , Status))[1])]">
<xsl:variable name="Quantity" select="sum(key('Movements', concat(ArticleNumber, '|', LogisticVariety, '|' , Status))/Quantity)"/>
<MovementLine>
<xsl:copy-of select="./*[not(name()='Quantity')]"/>
<Quantity>
<xsl:value-of select="$Quantity" />
</Quantity>
</MovementLine>
</xsl:for-each>
</Movement>
</xsl:for-each>
</MovementFileFlowRequest>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>`
Токовый выход:
`<?xml version="1.0" encoding="UTF-8"?>
<MovementFileFlowRequest>
<Movement>
<MovementLine>
<ArticleNumber>355</ArticleNumber>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
<Quantity>60</Quantity>
</MovementLine>
<MovementLine>
<ArticleNumber>129</ArticleNumber>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
<Quantity>10</Quantity>
</MovementLine>
</Movement>
<Movement>
<MovementLine>
<ArticleNumber>359</ArticleNumber>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
<Quantity>20</Quantity>
</MovementLine>
</Movement>
<Movement/>
</MovementFileFlowRequest>
`
Желаемый вывод:
`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MovementFileFlowRequest>
<Movement>
<MovementLine>
<ArticleNumber>355</ArticleNumber>
<Quantity>60</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
<MovementLine>
<ArticleNumber>129</ArticleNumber>
<Quantity>10</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
</Movement>
<Movement>
<MovementLine>
<ArticleNumber>359</ArticleNumber>
<Quantity>10</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
</Movement>
<Movement>
<MovementLine>
<ArticleNumber>359</ArticleNumber>
<Quantity>10</Quantity>
<LogisticVariety>2</LogisticVariety>
<Status>12</Status>
<DateFormatted>20190516</DateFormatted>
<Content/>
<LineReference/>
</MovementLine>
</Movement>
</MovementFileFlowRequest>`