Re: Хитрое преобразование
От:
Сим
Дата:
04.06.04 09:38
Оценка:
В связи с немногочисленностью ответов, пришлось покопаться в XSLT самому.
Если кому интересно, вот что получилось:
<!-- Copy all tree -->
<xsl:variable name="All">
<xsl:copy-of select="/"/>
</xsl:variable>
<!-- Get all dates -->
<xsl:variable name="Dates">
<xsl:for-each select="Price">
<Date><xsl:value-of select="./Date"/></Date>
</xsl:for-each>
</xsl:variable>
<!-- Sort Dates -->
<xsl:variable name="SortedDates">
<xsl:for-each select="msxsl:node-set($Dates)/Date">
<xsl:sort select="."/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<!-- eliminate duplicaates -->
<xsl:variable name="UniqueDates">
<xsl:for-each select="msxsl:node-set($SortedDates)/Date">
<xsl:variable name="here" select="position()"/>
<xsl:if test="$here=1 or ../Date[position() < $here][1] != .">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($UniqueDates)/Date">
<xsl:variable name="cd">
<xsl:value-of select="." />
</xsl:variable>
<Season>
<Date><xsl:value-of select="$cd" /></Date>
<xsl:for-each select="msxsl:node-set($All)//Price[Date=$cd]">
<Type>
<PriceValue><xsl:value-of select="./PriceValue" /></PriceValue>
<TypeValue><xsl:value-of select="./Type" /></TypeValue>
</Type>
</xsl:for-each>
</Season>
</xsl:for-each>
Однако я думаю что можно было сделать и покрасивше
Переместить
Удалить
Выделить ветку
Проголосовать
Пока на собственное сообщение не было ответов, его можно удалить.
Удалить
Проголосовать
Заголовок: