D
D
Dmitry Bystrov2019-09-14 14:56:17
XSL & XSLT
Dmitry Bystrov, 2019-09-14 14:56:17

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
f4bf82b1b185b17da141abc40a95b521.png
display the start time and title of the show, grouped by date.

m24_tv.xml
<?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>

m24_tv_style.xsl
<?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>

Now it turned out to group by date and display the names of the programs.
9201c44d9ead4847ab67a045840ec930.png
How can I get the transmission start time?
Transmission start time - property start=""in <programme>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Sartakov, 2019-09-14
@Teshuhack

<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 question

Ask a Question

731 491 924 answers to any question