这种划分源XML:复杂的“选择”
<root>
<!-- a and b have the same date entries, c is different -->
<variant name="a">
<booking>
<date from="2017-01-01" to="2017-01-02" />
<date from="2017-01-04" to="2017-01-06" />
</booking>
</variant>
<variant name="b">
<booking>
<date from="2017-01-01" to="2017-01-02" />
<date from="2017-01-04" to="2017-01-06" />
</booking>
</variant>
<variant name="c">
<booking>
<date from="2017-04-06" to="2017-04-07" />
<date from="2017-04-07" to="2017-04-09" />
</booking>
</variant>
</root>
我想组的三个变种,以便每个日期相同@from
和@to
每个变种要相对集中。
我的尝试是:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"></xsl:output>
<xsl:template match="root">
<variants>
<xsl:for-each-group select="for $i in variant return $i" group-by="booking/date/@from">
<group>
<xsl:attribute name="cgk" select="current-grouping-key()"/>
<xsl:copy-of select="current-group()"></xsl:copy-of>
</group>
</xsl:for-each-group>
</variants>
</xsl:template>
</xsl:stylesheet>
但是这给了太多组。 (如何)这可能实现?
你得到的输出是什么? – GavinBrelstaff
那么您使用哪种XSLT 2.0处理器?使用Saxon 9.8或任何其他XSLT 3.0处理器和“复合”分组键可能会更容易。另外,具有相同'date'元素的'variant'会发生什么,但是按不同的顺序?订单是否重要? –
@MartinHonnen目前我正在使用Saxon-HE 9.4.0.2J,但我可以轻松更新。 – topskip