Я пытаюсь принять этот вход Не удалось успешно преобразовать документ xml в другой.
<root>
<row>
<guestid>G1</guestid>
<splits>
<split>
<begin_date>2015-03-01</begin_date>
<end_date>2016-06-30</end_date>
<apples>A01</apples>
<oranges>BB01</oranges>
<percent>60</percent>
</split>
<split>
<apples>A02</apples>
<oranges>BB02</oranges>
<percent>40</percent>
</split>
</splits>
<splits>
<!-- No gap from previous. Starts the next day. -->
<split>
<begin_date>2015-07-01</begin_date>
<end_date>2015-09-30</end_date>
<apples>A55</apples>
<oranges>BB55</oranges>
<percent>75</percent>
</split>
<split>
<begin_date>2015-07-01</begin_date>
<end_date>2015-09-30</end_date>
<apples>A100</apples>
<oranges>BB100</oranges>
<percent>25</percent>
</split>
</splits>
<splits>
<!-- There is a gap.(between 2015-10-01 and 2016-01-31 This will be filled up with defaut splits. -->
<split>
<begin_date>2016-02-01</begin_date>
<end_date>2016-02-29</end_date>
<apples>A777</apples>
<oranges>BB777</oranges>
<percent>85</percent>
</split>
<split>
<begin_date>2016-02-01</begin_date>
<end_date>2016-01-31</end_date>
<apples>A200</apples>
<oranges>BB200</oranges>
<percent>15</percent>
</split>
</splits>
<splits>
<!-- There is a gap.(between 2015-10-01 and 2016-01-31 This will be filled up with defaut splits. -->
<split>
<begin_date>2016-04-01</begin_date>
<end_date>2016-04-30</end_date>
<apples>A777</apples>
<oranges>BB777</oranges>
<percent>85</percent>
</split>
<split>
<begin_date>2016-04-01</begin_date>
<end_date>2016-04-30</end_date>
<apples>A200</apples>
<oranges>BB200</oranges>
<percent>15</percent>
</split>
</splits>
<default_splits>
<!-- no percentage. Will always be 100 percent. Never split. -->
<default>>
<begin_date>2015-01-01</begin_date>
<apples>AD1111</apples>
<oranges>BB1111</oranges>
</default>
<default>
<begin_date>2015-07-01</begin_date>
<apples>A2222</apples>
<oranges>BB2222</oranges>
</default>
<default>
<begin_date>2015-11-01</begin_date>
<apples>A8888</apples>
<oranges>BB8888</oranges>
</default>
</default_splits>
</row>
</root>
Раскол узел не обязательно отсортирован. Исходный xml был предварительно запрограммирован для каждого чтения. Ожидаемый конечный результат выглядит следующим образом: Однако даты начала и окончания даты в узле расщепления можно ожидать, что они будут такими же.
Конечный результат ожидается следующим образом:
<?xml version="1.0" encoding="UTF-8"?>
<!--Output XML -->
<root>
<row>
<guestid>G1</guestid>
<splits>
<!-- Reg -->
<split>
<begin_date>2015-03-01</begin_date>
<end_date>2016-06-30</end_date>
<apples>A01</apples>
<oranges>BB01</oranges>
<percent>60</percent>
</split>
<split>
<apples>A02</apples>
<oranges>BB02</oranges>
<percent>40</percent>
</split>
</splits>
<splits>
<!-- Reg no gap between prior split and this split. -->
<split>
<begin_date>2015-07-01</begin_date>
<end_date>2015-09-30</end_date>
<apples>A55</apples>
<oranges>BB55</oranges>
<percent>75</percent>
</split>
<split>
<begin_date>2015-07-01</begin_date>
<end_date>2015-09-30</end_date>
<apples>A100</apples>
<oranges>BB100</oranges>
<percent>25</percent>
</split>
</splits>
<!-- aded from default to cover the gap.-->
<splits>
<!-- based on default-->
<!-- based on default -->
<split>
<begin_date>2015-10-01</begin_date>
<end_date>2015-10-31</end_date>
<apples>AD1111</apples>
<oranges>BB1111</oranges>>
<percent>100</percent>
</split>
</splits>
<!-- added from the second default split. But ended before start of regular split. -->
<splits>
<!-- Default -->
<split>
<begin_date>2015-11-01</begin_date>
<end_date>2016-01-31</end_date6
<apples>A8888</apples>
<oranges>BB8888</oranges>
<percent>100</percent>
</split>
</splits>
<splits>
<!-- Reg -->
<split>
<begin_date>2016-02-01</begin_date>
<end_date>2016-02-29</end_date>
<apples>A777</apples>
<oranges>BB777</oranges>
<percent>85</percent>
</split>
<split>
<begin_date>2016-02-01</begin_date>
<end_date>2016-02-29</end_date>
<apples>A200</apples>
<oranges>BB200</oranges>
<percent>15</percent>
</split>
</splits>
<splits>
<!-- Gap Filled up -->
<!-- based on default -->
<split>
<begin_date>2016-03-01</begin_date>
<end_date>2016-03-31</end_date>
<apples>A8888</apples>
<oranges>BB8888</oranges>
<percent>100</percent>
</split>
</splits>
<splits>
<!-- Reg -->
<split>
<begin_date>2016-04-01</begin_date>
<end_date>2016-04-30</end_date>
<apples>A777</apples>
<oranges>BB777</oranges>
<percent>85</percent>
</split>
<split>
<begin_date>22016-04-01</begin_date>
<end_date>2016-04-30</end_date>
<apples>A200</apples>
<oranges>BB200</oranges>
<percent>15</percent>
</split>
</splits>
<!--added as there is an end date on last row. default values active to be used-->
<splits>
<!-- from default -->
<split>
<begin_date>2016-05-01</begin_date>
<apples>A8888</apples>
<oranges>BB8888</oranges>
<percent>100</percent>
</split>
</splits>
</row>
Я тред здание следующее. Но я застреваю из-за ошибки.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/root/row">
<row>
<xsl:for-each select="splits">
<xsl:sort select="xs:date(split/begin_date[1])" order="descending"/>
<xsl:for-each select=".">
<newsplit>
<begin_date><xsl:value-of select="begin_date" /> </begin_date>
<end_date><xsl:value-of select="end_date" /></end_date>
<apples><xsl:value-of select= "apples" /></apples>
<oranges><xsl:value-of select= "oranges" /></oranges>
<pct><xsl:value-of select= "percent" /></pct>
</newsplit>
</xsl:for-each>
</xsl:for-each>
</row>
</xsl:template>
</xsl:stylesheet>
ошибка встречается это - последовательность из более чем одного элемента не допускается в качестве значения в «брошено как» выражение [22]
Я знаю, что я все еще далеко от завершая это. Но я застрял в этом пункте. Будем оценивать любые отзывы и помощь. Спасибо.
Я думаю, вам нужно использовать 'xsl: выполнить-sort' (https://www.w3.org/TR/xslt20/#creating-sorted-sequence). – potame
Спасибо, посмотрим. – StillStumbling