Last active
February 29, 2024 17:04
-
-
Save tohuuuuu/11fb13a5697e377161de11b5a5fe02e6 to your computer and use it in GitHub Desktop.
XSLT Stylesheet to create single nfo files from VideoStation metadata exported to XML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <xsl:stylesheet | |
| version="2.0" | |
| xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
| xmlns:xhtml="http://www.w3.org/1999/xhtml" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
| <!-- Sets the root directory for the output --> | |
| <xsl:variable | |
| name="outpathprefix" | |
| select="'/tmp/videodata-nfo-out'" /> | |
| <xsl:template match="/videodata_tmp/row"> | |
| <!-- Builds the output path and nfo filename based on original name --> | |
| <xsl:variable | |
| name="nfopath" | |
| select="encode-for-uri(concat(substring-before(path,'.mp4'), '.nfo'))" /> | |
| <!-- Combines output prefix and output path --> | |
| <xsl:variable | |
| name="outpath" | |
| select="concat($outpathprefix, $nfopath)" /> | |
| <!-- Write nfo file for each metadata record --> | |
| <xsl:result-document | |
| href="{$outpath}" | |
| exclude-result-prefixes="xsl xhtml xsi" | |
| encoding="UTF-8" | |
| indent="yes"> | |
| <xsl:element name="movie"> | |
| <xsl:apply-templates select="title" /> | |
| <xsl:apply-templates select="summary" /> | |
| <xsl:apply-templates select="filename" /> | |
| <xsl:element name="filenameandpath"> | |
| <xsl:value-of select="path" /> | |
| </xsl:element> | |
| <xsl:apply-templates select="uniqueid" /> | |
| <xsl:apply-templates select="genre" /> | |
| <xsl:apply-templates select="record_time" /> | |
| </xsl:element> | |
| </xsl:result-document> | |
| </xsl:template> | |
| <!-- Separate Templates for record data fields --> | |
| <xsl:template | |
| match="filename"> | |
| <xsl:copy-of copy-namespaces="no" select="." /> | |
| </xsl:template> | |
| <xsl:template | |
| match="uniqueid"> | |
| <xsl:copy copy-namespaces="no"> | |
| <xsl:attribute name="type"><xsl:text>home</xsl:text></xsl:attribute> | |
| <xsl:attribute name="default"><xsl:text>true</xsl:text></xsl:attribute> | |
| <xsl:value-of select="." /> | |
| </xsl:copy> | |
| </xsl:template> | |
| <xsl:template match="title"> | |
| <xsl:element name="title"> | |
| <xsl:value-of select="." /> | |
| </xsl:element> | |
| <xsl:element name="showtitle"> | |
| <xsl:value-of select="." /> | |
| </xsl:element> | |
| <xsl:element name="sorttitle"> | |
| <xsl:value-of select="." /> | |
| </xsl:element> | |
| </xsl:template> | |
| <xsl:template | |
| match="summary"> | |
| <xsl:element name="plot"> | |
| <xsl:value-of select="." /> | |
| </xsl:element> | |
| </xsl:template> | |
| <xsl:template match="genre"> | |
| <xsl:for-each select="tokenize(., '\|')"> | |
| <xsl:element name="genre"> | |
| <xsl:value-of select="." /> | |
| </xsl:element> | |
| </xsl:for-each> | |
| </xsl:template> | |
| <xsl:template match="record_time"> | |
| <xsl:element name="dateadded"> | |
| <xsl:value-of select="replace(., '(\d{4}-\d{2}-\d{2}).*', '$1')" /> | |
| </xsl:element> | |
| </xsl:template> | |
| </xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment