Hi,
I'm on Tridion Doc 14 SP4. I wanted to use the XML Write Plugin to rewrite problematic legacy conref formats - XMetaL used an unsupported structure, and we have now moved to Oxygen.
I came up with this:
<plugin name="CORRECT.CONREF.LINKS" handler="BlobSetXmlNode" ishcondition="CurrentAction in ('CheckOut') and (EDT='EDTXML')"> <description>Corrects conref attributes</description> <initialize> <parameters> <parameter name="OnNodeXPath">(//*/@conref[contains(., '#') and not(contains(., '/'))])</parameter> <parameter name="NodeType">attribute</parameter> <parameter name="NodeName">conref</parameter> <parameter name="OverwriteExisting">No</parameter> <parameter name="Value"> ??? </parameter> </parameters> </initialize> </plugin>
However, after reading the docs, it doesn't look like the Value parameter has any types that handle something complex like value rewrites.
Is there another, simple way to achieve this kind of rewrite on checkout?
Note that I do have some XSLT ready (code below) if this can be leveraged on topic checkout. I have also contacted Oxygen support to see if they have the native ability to run XSLT when editable topics are opened.
Thanks in advance for any advice!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <!-- Identity template that copies everything as is --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!-- Template matching elements with a 'conref' attribute which does not contain '/' --> <xsl:template match="*[@conref and not(contains(@conref, '/'))]"> <xsl:copy> <!-- Apply templates to all attributes other than 'conref' --> <xsl:apply-templates select="@*[local-name()!='conref']"/> <!-- Special treatment for the 'conref' attribute --> <xsl:attribute name="conref"> <xsl:variable name="originalConref" select="@conref"/> <!-- Perform replacement here --> <xsl:choose> <!-- Test if the 'conref' already follows the pattern (use XSLT 2.0 regex if available) --> <xsl:when test="matches($originalConref, '^[A-Z0-9\-]+\#[A-Z0-9\-]+\/.*$')"> <xsl:value-of select="$originalConref"/> </xsl:when> <!-- If not, apply custom logic to adjust the value --> <xsl:otherwise> <xsl:value-of select="concat(substring-before($originalConref, '#'), '#', substring-before($originalConref, '#'), '/')"/> <xsl:value-of select="substring-after($originalConref, '#')"/> </xsl:otherwise> </xsl:choose> </xsl:attribute> <!-- Apply templates to all children nodes --> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>