Skip to content

Commit

Permalink
Add XSLT stylesheet that rewrites SegmentTemplate media attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
emarsden committed Oct 28, 2023
1 parent bcfffe6 commit 09fd3f9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/fixtures/rewrite-resolution.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mpd="urn:mpeg:dash:schema:mpd:2011">
<xsl:output method="xml" indent="yes"/>

<!-- Default action (unless a template below matches): copy -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<!-- This stylesheet modifies the @media attribute on the SegmentTemplate of the AdaptationSet
with id=2, setting it to the string '1080p'. This is a way of overriding the DASH template
resolution process. A template might be using "$RepresentationID$_$Number$.mp4" and you want
to force the RepresentationID to be 1080p for example.
Note that simple XPath expressions like "//AdaptationSet[@id=2]/SegmentTemplate/@media" fail
on an MPD manifest that defines a namespace (@xmlns on the MPD element, which is very often
present). This is why we use local-name().
-->
<xsl:template match="//node()[local-name()='AdaptationSet' and @id='2']/node()[local-name()='SegmentTemplate']/@media">
<xsl:attribute name="media">
<xsl:value-of select="'1080p_$Number$'"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 09fd3f9

Please sign in to comment.