This article will focus on achieving page editor experience for a static page (page whose html content resides within the sitecore item fields) using XSL rendering in Sitecore.
Questions like when to use XSL rendering and is it suggested to use XSL rendering in Sitecore MVC is out of this tutorial’s scope. If you are looking for such info then this blog post could help you.
Create an XSLT file with below content and place it inside the website folder in the path: Website/xsl/Home.xslt.
Home.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sc="http://www.sitecore.net/sc"
xmlns:sql="http://www.sitecore.net/sql"
exclude-result-prefixes="sc sql">
<!-- output directives -->
<xsl:output method="html" indent="no" encoding="UTF-8" />
<!-- sitecore parameters -->
<xsl:param name="lang" select="'en'"/>
<xsl:param name="id" select="''"/>
<xsl:param name="sc_item"/>
<xsl:param name="sc_currentitem"/>
<!-- entry point -->
<xsl:template match="*">
<div>
<sc:text field="text" />
</div>
</xsl:template>
</xsl:stylesheet>
Now go to Home item and edit the ‘text’ field using the Edit html link. Enter some html content to it and save. Now browse the home item in the browser. You can see the content of ‘Text’ field of Home item being rendered on the page.
Then login to Sitecore as Page Editor and try to edit this page. You will be able to edit and save the edited content. Once you save it, all your changes will reflect in the Text field. That’s it! Now you can directly edit this page content, save and publish without using content editor.
The Home item uses the ‘Sample Item’ template (/sitecore/templates/Sample/Sample Item) which has by default two data fields – ‘Title’ (of type text) and ‘Text’ (Rich Text).
The name of the field (‘Text’) is mentioned in the XSLT file what we have created and then we have passed the Home item as data source to the XSL rendering. Thus the edited content is moved between the page and Text field.