0

I just can't figure out how I become able to match a specified text. So I have the following xml-data. And I want to add more display-name depending what channel.

    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- EPG XMLTV FILE CREATED BY Take-a-LUG TEAM- (c) 2020 Bastian Kleinschmidt -->
    <!-- created on 2022-01-09 23:17:01.019522 -->
    <tv generator-info-name="Takealug EPG Grabber Ver. 1.1.2+matrix" generator-info-url="https://github.com/DeBaschdi/service.takealug.epg-grabber">
            
        <channel id="ARD.de">
                    <display-name lang="de">Das Erste</display-name>          
        </channel>
        <channel id="ZDF.de">
                    <display-name lang="de">ZDF</display-name>
        </channel>
        <channel id="RTL.de">
                    <display-name lang="de">RTL</display-name>
        </channel>
        <channel id="Sat1.de">
                    <display-name lang="de">SAT.1</display-name>
         </channel>
        <channel id="Pro7.de">
                    <display-name lang="de">ProSieben</display-name>
        </channel>
        <channel id="Kabel.de">
                    <display-name lang="de">kabel eins</display-name>
        </channel>
 </tv>

As you can see I have a specified channel-id and display-name for every channel. Now I want to have f.e. additional to <display-name>Das Erste</display-name>, also <display-name>Das Erste HD</display-name>. For ZDF, ZDF HD, or for 'Kabel Eins' additionaly to the HD suffix auch 'Kabel 1' as display-name. And there are some other channels where I want to do some adjustments. I tried some things, f.e.:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

 <xsl:template match="channel/display-name[contains('Das Erste')]">
        <xsl:copy>
   <display-name>Das Erste HD</display-name>
    </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

But nothing happens, so I think the key for the solution is matching the right channel.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Alex Mutschl
  • 27
  • 1
  • 7

1 Answers1

1

Change:

<xsl:template match="channel/display-name[contains('Das Erste')]">

to:

<xsl:template match="channel[contains(display-name, 'Das Erste')]">

See:
https://www.w3.org/TR/1999/REC-xpath-19991116/#predicates
https://www.w3.org/TR/1999/REC-xpath-19991116/#function-contains

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Hello, great, thanks. I had to add xsl:copy-of select="." before the display-name. now it works as I want -> using the current display-name and adding other. Is there a comfortablier way to add more child elements then having to use for every new name inside a channel the display-name element? – Alex Mutschl Jan 19 '22 at 07:51
  • I am afraid I don't fully understand what you're asking. As you should know from your previous question, you can add child element in two ways: (1) match the parent element, copy it and within this copy apply templates to (or copy) existing attributes and child elements, and add more elements; or (2) match some child element that is known to exist, copy it, and add sibling elements beside this copy. – michael.hor257k Jan 19 '22 at 08:07
  • Maybe my bad english sometimes makes it difficult to express what I mean, sorry. But I did understand the comparison with my other question. In any case, I managed to create a code that answers both my questions. Thanks for all the help here. – Alex Mutschl Jan 19 '22 at 21:13