Created
November 1, 2023 13:41
-
-
Save Denyerec/cdd82e9ff3f6ce967b8f13a161da70c7 to your computer and use it in GitHub Desktop.
Transpose CaptureOne Keywords to IPTC Description Field
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
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" | |
xmlns:user="urn:my-scripts" | |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" | |
xmlns:lightroom="http://ns.adobe.com/lightroom/1.0/" | |
xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" | |
version="1.0"> | |
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="utf-8"/> | |
<xsl:strip-space elements="*"/> | |
<xsl:template match="node()|@*" name="identity"> | |
<xsl:copy> | |
<xsl:apply-templates select="node()|@*"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- copy into: | |
/rdf:RDF/rdf:Description/dc:description/rdf:Alt | |
things we find in | |
/rdf:RDF/rdf:Description/lightroom:hierarchicalSubject/rdf:Bag/rdf:li | |
after passing it through a simple JS function that will take only the last heirarchial keyword (Assuming last portion after last | char) | |
--> | |
<msxsl:script implements-prefix='user' language='JavaScript'> | |
<![CDATA[ | |
function lastHierarchicalKeyword(str){ | |
return (str.substr(str.lastIndexOf('|')+1)); | |
} | |
]]> | |
</msxsl:script> | |
<xsl:template match="rdf:Description/*[1][not(../dc:description)]"> | |
<dc:description> | |
<xsl:call-template name="add-strings"/> | |
</dc:description> | |
<xsl:call-template name="identity"/> | |
</xsl:template> | |
<xsl:template match="dc:description"> | |
<xsl:copy> | |
<xsl:call-template name="add-strings"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template name="add-strings"> | |
<rdf:Alt> | |
<rdf:li> | |
<xsl:for-each select="//lightroom:hierarchicalSubject/rdf:Bag/rdf:li"> | |
<xsl:value-of select="user:lastHierarchicalKeyword(string(node())" /> | |
<xsl:if test="position() != last()">,</xsl:if> | |
</xsl:for-each> | |
</rdf:li> | |
</rdf:Alt> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment