Update topics on checkout

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>

emoji
Parents
  • Hi Charles,

    Legacy conversion, depending on your defined data set (the whole Repository, latest versions only, only draft not released, source language only, etc) can be a challenge.

    Your suggestion over IWrite plugin would attempt a conversion on CheckIn/Update, so in essence on change of the xml. I don't think we have standard plugins that cover your "value replace" idea, definitely not over a custom XSLT. If you think this route is the one to transform your legacy, then I think you need to write a custom IWrite plugin implementation.

    If you want to shed the legacy in one go, you could consider crawling your repository and force these changes. Also there are multiple possibilities, if you allow me to call out one to illustrate the idea, then I would point to https://github.com/RWS/ISHRemote/blob/master/Doc/ReleaseNotes-ISHRemote-0.13.md#repository-corrections 

    • The Get-IshFolderContent can be tweaked to your defined data set
    • And instead of the "Add-IshBackgroundTask -EventType "SMARTTAG"" sample you could do a Get-IshDocumentObjData, your custom transformation, and when you are ready a Set-IshDocumentObj. To validate you can actually save a before and after transformation on your file system so you can validate/QA your efforts before the final Set-IshDocumentObj cmdlet.

    Have a read of that release notes section.

    Best wishes,
    Dave

    emoji
Reply
  • Hi Charles,

    Legacy conversion, depending on your defined data set (the whole Repository, latest versions only, only draft not released, source language only, etc) can be a challenge.

    Your suggestion over IWrite plugin would attempt a conversion on CheckIn/Update, so in essence on change of the xml. I don't think we have standard plugins that cover your "value replace" idea, definitely not over a custom XSLT. If you think this route is the one to transform your legacy, then I think you need to write a custom IWrite plugin implementation.

    If you want to shed the legacy in one go, you could consider crawling your repository and force these changes. Also there are multiple possibilities, if you allow me to call out one to illustrate the idea, then I would point to https://github.com/RWS/ISHRemote/blob/master/Doc/ReleaseNotes-ISHRemote-0.13.md#repository-corrections 

    • The Get-IshFolderContent can be tweaked to your defined data set
    • And instead of the "Add-IshBackgroundTask -EventType "SMARTTAG"" sample you could do a Get-IshDocumentObjData, your custom transformation, and when you are ready a Set-IshDocumentObj. To validate you can actually save a before and after transformation on your file system so you can validate/QA your efforts before the final Set-IshDocumentObj cmdlet.

    Have a read of that release notes section.

    Best wishes,
    Dave

    emoji
Children