Creating a Content Upgrade with Protean CMS - Eonic/ProteanCMS GitHub Wiki
#Prerequsites
You have the most recent version of ProteanCMS locally and project that you're planning to complete the content upgrade for.
#Creating the Content Upgrade File
Navigate to C:\HostingSpaces\ewcommon_v5-1\xsl\Upgrades, in this file directory are example files for you to duplicate and use.
In my examples going forward I'm going to be referencing and using the TraningCourse.xsl.
Navigate to Visual Studio now and go to site/modules/[xsl type e.g. trainingcourse]/ and copy the example file here. If this directory doesn't already exist you can create it.
Open the file that you've just created so we can start making changes.
Here there will already be some XML code that I will talk through here.
Firstly, you have the following code which will go through the XML Schema that you're targeting and re-write it all exactly as is with some extra handling for <img>
and <br>
tags.
<xsl:template match="/instance">
<instance>
<xsl:for-each select="*">
<xsl:apply-templates select="." mode="writeNodes"/>
</xsl:for-each>
</instance>
</xsl:template>
<xsl:template match="*" mode="writeNodes">
<xsl:element name="{name()}">
<!-- process attributes -->
<xsl:for-each select="@*">
<!-- remove attribute prefix (if any) -->
<xsl:attribute name="{name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates mode="writeNodes"/>
</xsl:element>
</xsl:template>
<xsl:template match="img" mode="writeNodes">
<img src="{@src}" width="{@width}" height="{@height}" alt="{@alt}" class="{@class}" />
</xsl:template>
<xsl:template match="br" mode="writeNodes">
<br/>
</xsl:template>
Now what we're going to want to do is add another rule so that when we're rewriting the XML we can replace any tags or attributes with something else so that the output will be what we want.
Below all of the code that I've just spoken about above I'm going to copy and paste the main block at the bottom of the file.
In this example here I'm targeting the tag CourseName and renaming all instances of it to Name: ##Original
<xsl:template match="*" mode="writeNodes">
<xsl:element name="{name()}">
<!-- process attributes -->
<xsl:for-each select="@*">
<!-- remove attribute prefix (if any) -->
<xsl:attribute name="{name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates mode="writeNodes"/>
</xsl:element>
</xsl:template>
##Changed
<xsl:template match="CourseName" mode="writeNodes">
<xsl:element name="Name">
<!-- process attributes -->
<xsl:for-each select="@*">
<!-- remove attribute prefix (if any) -->
<xsl:attribute name="{name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates mode="writeNodes"/>
</xsl:element>
</xsl:template>
This is just an example but feel free to make the necessary changes that would be required for your own Content Upgrade.
As a quick conclusion to the logic here:
- We're targeting the XML that we want changed.
- Rewritting everything in the document.
- Changing the attributes/tags to our desired ones.
Now that the changes have been made to our file we can now move on to testing the output to make sure that it is correct.
#Testing the Content Upgrade Make sure that the file that you've been working on is saved and launch the project locally.
Navigate to the admin portal and, in the header, select Setting > File Import.
Now on the File Import page you can select the file that you've just created.
Next we're going to want to set the Operational Mode to Test and the Response Xml to Yes so that we can see the full output of the changes that have happened.
Once these have been completed you can select upload and you should see a response be generated.
If after reading this response you're not happy with how it looks you can go back and make some changes to the original file and repeat this process.
Once you're happy set the Operational Mode to Full Import and Response Xml to Yes for the Content upgrade to be performed on your site.
Congratulations your Content Upgrade has now been completed!