Search

This link showed me an easy way to embed youtube videos, I’ve tested it with a markdown field and it seems to work a treat.

This is exactly the sort of thing I’m interested in, the easiest way to embed various content in my article bodies, without needing multiple fields for different content types.

@rob, you gonna make an xslt utility out of it?

Also, can you explain how you’ve achieved this? It mentions extra parameters, have you been able to create these?

@designermonkey - I was tempted to make a utility for this site, but given that it isn’t my own work I thought it most fair to link out to the author. I can’t claim any credit, but I suppose I could reference the author in the utility comments.

I haven’t tried the extra parameters to be honest, I just did a very quick test and then posted here when it worked.

As for getting it to work, I basically copied the whole youtube template from the stylesheet on that site into my typography.xsl with the ninja technique base bits, and added mode=html to the template tag so that it would only be applied when the youtube tag was part of my article body which is called with mode=html.

Sorry if this isn’t the worlds best explanation, it worked so easily for me that I assume that it would be no bother for others here.

Well this ninja technique business is getting more interesting by the second!!

I’ve been able to get a template that matches a paragraph with a youtube link at the start and turn that into an embedded player.

So you can just drop a youtube link into content in it’s own paragraph e.g. just on it’s own line in markdown, and it’ll create the player. This must have a myriad of other uses, now I can see why the excitement around the ninja technique.

I’ll clean this up and post a link to pastie or such shortly.

The following XSLT can will match a paragraph tag with a youtube link as the first bit of content e.g.

<p>http://www.youtube.com/watch?v=nFicqklGuB0</p>

And return a paragraph with a full embedded player inside.

<xsl:template match="p[starts-with(., 'http://www.youtube.com/watch?v=')]" mode="html">
<p><xsl:element name="object">
    <xsl:attribute name="type">application/x-shockwave-flash</xsl:attribute>
    <xsl:attribute name="width">560</xsl:attribute>
    <xsl:attribute name="height">350</xsl:attribute>
    <xsl:attribute name="class">youtube-embed</xsl:attribute>
    <xsl:attribute name="data">
        http://www.youtube.com/v/<xsl:value-of select="normalize-space(substring-after(., 'http://www.youtube.com/watch?v='))"/>
    </xsl:attribute>
    <xsl:element name="param">
        <xsl:attribute name="name">movie</xsl:attribute>
        <xsl:attribute name="value">
            http://www.youtube.com/v/<xsl:value-of select="normalize-space(substring-after(., 'http://www.youtube.com/watch?v='))"/>
        </xsl:attribute>
    </xsl:element>
    <xsl:element name="param">
        <xsl:attribute name="name">wmode</xsl:attribute>
        <xsl:attribute name="value">transparent</xsl:attribute>
    </xsl:element>
</xsl:element></p>

Neato, but why use mode="html" here?

It’s a way of pseudo-namespacing. In case you include the template in your master.xsl (visible to all pages) but only want to apply it to certain paragraphs. You might want another apply-templates on another set of paragraphs with an entirely different set of rules.

nice rob! i’m sure this can be used as an example to embed other types of content…too bad xslt 1 doesn’t have regular expressions…

You might want another apply-templates on another set of paragraphs with an entirely different set of rules.

I think my focus is too narrow :-)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details