Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An XSLT transform I use for converting itt-formatted subtitles to srt-formatted subtitles
<?xml version="1.0"?>
<!--
This will convert itt-formatted subtitles to srt-formatted subtitles (or captions, if you prefer that)
Use it like so (using xsltproc in this example, feel free to use whatever engine you like):
# xsltproc itt-to-srt.xslt input_in_itt.itt > output_in_srt.srt
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ttp="http://www.w3.org/ns/ttml#parameter"
xmlns:tt_feature="http://www.w3.org/ns/ttml/feature/"
xmlns:tts="http://www.w3.org/ns/ttml#styling"
xmlns:tt_extension="http://www.w3.org/ns/ttml/extension/"
xmlns:tt_profile="http://www.w3.org/ns/ttml/profile/"
xmlns:ttm="http://www.w3.org/ns/ttml#metadata"
xmlns:ry="http://namespace.itunes.apple.com/itt/ttml-extension#ruby"
xmlns="http://www.w3.org/ns/ttml"
ttp:frameRate="50"
ttp:frameRateMultiplier="1 1"
xml:lang="en" xmlns:tt="http://www.w3.org/ns/ttml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
ttp:dropMode="nonDrop"
ttp:timeBase="smpte"
>
<xsl:output method="text" omit-xml-declaration="yes" indent="no" />
<xsl:strip-space elements="*" />
<xsl:template match="/tt:tt/tt:body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/tt:tt/tt:head">
</xsl:template>
<xsl:template match="tt:div/tt:p/tt:span/tt:br">
<xsl:text>&#xa;</xsl:text>
</xsl:template>
<xsl:template match="tt:div">
<xsl:for-each select="tt:p">
<xsl:value-of select="position()"/>
<xsl:text>&#xa;</xsl:text>
<xsl:value-of select='substring(@begin, 0, 9)' />,<xsl:value-of select='concat(substring(@begin, 10, 12), 0)' /> --> <xsl:value-of select='substring(@end, 0, 9)' />,<xsl:value-of select='concat(substring(@end, 10, 12), 0)' />
<xsl:text>&#xa;</xsl:text>
<xsl:apply-templates select="tt:span"/>
<xsl:text>&#xa;</xsl:text>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.