2

I have just started trying to get my head around Symphony and XML/XSL based templating etc (I don't even know the correct terminology so forgive me).

I have a Videos section in Symphony, and one of the Input fields is for a YouTube URL. I obviously can't just write <a href="<xsl:value-of select="youtube-url"/>">Video</a> but I'm really not sure how it SHOULD be done.

I did some Googling and found that xml/xsl or whatever supports variables so I thought that was a good shout, but as you can see in my code example below, whatever I have done, it has failed. Maybe I'm just using variables wrong? I don't know.

I just need my Youtube-URL to be in the space that I currently have {$youtube}

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="../utilities/master.xsl"/>
<xsl:variable name="youtube"> 
    <xsl:value-of select="youtube-url"/>
</xsl:variable>
<xsl:template match="data">
    <div class="video-container">
        <xsl:apply-templates select="videos/entry"/>
    </div>
</xsl:template>
<xsl:template match="videos/entry">
    <div class="video">
        <div class="video-title"><xsl:value-of select="title"/></div>
        <div class="video-player">
            {$youtube}
        </div>
        <div class="video-desc"><xsl:value-of select="description"/></div>
    </div>
</xsl:template>
</xsl:stylesheet>
user2992596
  • 181
  • 2
  • 12
  • Can you update your question and include your input XML (either the entire document or a useful snippet)?. Then I am sure your question can be answered. – Mathias Müller Nov 21 '13 at 15:57

1 Answers1

1

You can't write

<a href="<xsl:value-of select="youtube-url"/>">Video</a> 

but you can write

<a href="{youtube-url}">Video</a> 

or

<a href="{$youtube}">Video</a> 

That's an attribute value template.

It only works in within attributes, though. You cannot use it in other text. (something like <div class="video-player">{$youtube}</div> will not work - use <xsl:value-of> instead.)

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • Woah man. You've blown my mind. I read that somewhere else, and stupidly I tested it by just pasting in {youtube-url}, which just outputted {youtube-url}, but it works when its in the href attr. Thank you man! - footnote: I am using 'man' gender ambiguously. – user2992596 Nov 21 '13 at 16:04
  • Of course in your case the variant that outputs the `$youtube` variable doesn't make sense, as the variable contents is fixed. – Tomalak Nov 21 '13 at 16:08
  • I know what you mean. :) – Tomalak Nov 21 '13 at 16:42