Answer the question
In order to leave comments, you need to log in
How to get parent element property using XSLT?
Hello!
I need to XSL transform an XML file to have the following structure: I want to
display the start time and title of the show, grouped by date.
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="m24_tv_style.xsl"?>
<tv generator-info-name="Generator/0.01" generator-info-url="http://xmltv.s-tv.ru">
<channel id="MOSCOW-24s">
<display-name lang="ru">МОСКВА-24 (сайт)</display-name>
</channel>
<programme start="20181001060000 +0400" channel="MOSCOW-24s">
<title lang="ru">УТРЕННЕЕ ВЕЩАНИЕ</title>
<date>2018-10-01</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001100000 +0400" channel="MOSCOW-24s">
<title lang="ru">НОВОСТИ<icon class='YhYho'></icon></title>
<date>2018-10-01</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001101500 +0400" channel="MOSCOW-24s">
<title lang="ru">СПЕЦИАЛЬНЫЙ РЕПОРТАЖ. ДОМ СВЯЗИ 12+</title>
<date>2018-10-01</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001103500 +0400" channel="MOSCOW-24s">
<title lang="ru">СПЕЦИАЛЬНЫЙ РЕПОРТАЖ КРУПНАЯ РЫБА 12+</title>
<date>2018-10-02</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001110000 +0400" channel="MOSCOW-24s">
<title lang="ru">НОВОСТИ<icon class='YhYho'></icon></title>
<date>2018-10-02</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001113000 +0400" channel="MOSCOW-24s">
<title lang="ru">КЛИМАТ-КОНТРОЛЬ 12+</title>
<date>2018-10-02</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001114500 +0400" channel="MOSCOW-24s">
<title lang="ru">НОВОСТИ<icon class='YhYho'></icon></title>
<date>2018-10-03</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001120000 +0400" channel="MOSCOW-24s">
<title lang="ru">НОВОСТИ<icon class='YhYho'></icon></title>
<date>2018-10-03</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<programme start="20181001123000 +0400" channel="MOSCOW-24s">
<title lang="ru">НОВОСТИ<icon class='YhYho'></icon></title>
<date>2018-10-03</date>
<video></video>
<category lang="ru">Инфо</category>
</programme>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:key name="dates" match="programme" use="date"/>
<xsl:template match="/">
<xsl:for-each select="//programme[generate-id(.)=generate-id(key('dates', date)[1])]">
<xsl:value-of select="date"/>
<xsl:value-of select="$newline"/>
<xsl:for-each select="key('dates', date)">
<xsl:value-of select="title"/>
<xsl:value-of select="$newline"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
start=""
in <programme>
Answer the question
In order to leave comments, you need to log in
<xsl:for-each select="key('dates', date)">
<xsl:value-of select="title"/>
<xsl:value-of select="$newline"/>
<xsl:value-of select="@start"/>
</xsl:for-each>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question