Extending C1

Topics: General, XSLT
Jun 11, 2011 at 12:47 AM

I currently have an ecommerce site that I use that for the most part is xslt driven, that said I would like to take all the xsl files and import them into C1 XSLT Function to be used in my pages. my issue I am having that I can't wrap my head around is registering the xslns tags. I am a windows/asp.net developer so xslt is very new and learning more and more everyday. is there some documents or a walkthrough I could follow?

here is an example xslt package that I am trying to integrate

<?xml version="1.0" standalone="yes" ?>
<package version="2.1" displayname="Staff Page" debug="false">

 <query name="StaffArticles" rowElementName="Article">
        <sql>
            <![CDATA[
                select StaffID, Name, Title, Bio, Phone, FAX, EMail, DisplayOrder, Wholesale, ExtensionData from Staff with (nolock)
                where Published=1 and Deleted=0
                order by DisplayOrder, Name desc
            ]]>
        </sql>
    </query>

    <PackageTransform>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xre="urn:xre" exclude-result-prefixes="xre">
         <xsl:output method="html" omit-xml-declaration="yes" />

            <xsl:param name="LocaleSetting" select="/root/Runtime/LocaleSetting" />
            <xsl:param name="WebConfigLocaleSetting" select="/root/Runtime/WebConfigLocaleSetting" />

            <xsl:template match="/">
                    <table width="100%" cellpadding="2" cellspacing="0" border="0">
                        <xsl:apply-templates select="/root/StaffArticles/Article" />
                    </table>
                <table width="100%" cellpadding="2" cellspacing="0" border="0">
                </table>

            </xsl:template>

            <xsl:template match="Article">
                    <tr>
                        <td align="left" valign="top">
      <xsl:value-of select="xre:LookupImage(StaffID, 'staff', 'medium', 0)" disable-output-escaping="yes"/>
                        </td>
      <td align="left" valign="top">
      <b><xsl:value-of select="Name" disable-output-escaping="yes"/></b>
      <br/><br/>
      <xsl:value-of select="Bio" disable-output-escaping="yes"/>
      </td>
                    </tr>
     <tr><td colspan="2" height="5"><img src="images/spacer.gif" width="10" height="5"/></td></tr>
            </xsl:template>
           
        </xsl:stylesheet>
    </PackageTransform>
</package>

as you can see there is a xre tag to register somewhere and also all the paths start with /root/ I am assuming I will have to change them to /Page/ but not to sure. again xslt is new to me but liking it

Jun 24, 2011 at 7:16 AM

SteelTownIT,
If we talking about xre tag / xslt.. - such functionality could be done at least in 2 ways:
1) C# in XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl in lang"
	xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
	xmlns:lang="http://www.composite.net/ns/localization/1.0"
	xmlns:f="http://www.composite.net/ns/function/1.0"
	xmlns:csharp="http://c1.composite.net/csharp"
	xmlns="http://www.w3.org/1999/xhtml">

notice xmlns:csharp here, instead csharp you can write any non-used name.

than:

	<msxsl:script implements-prefix="csharp" language="C#" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
		<msxsl:assembly name="Composite"/>
		<msxsl:using namespace="Composite.Core.ResourceSystem"/>
		<![CDATA[
		public string Localize(string providerName, string label)
		{
			return StringResourceSystemFacade.GetString(providerName, label);
		}
	]]>
	</msxsl:script>

and u can use it:

<xsl:value-of select="csharp:Localize('Composite.Community.Extranet', 'LoginStatus.Login')" />

2) XSLT extentions (my favourite, more clean and nice):
In App_Data\Composite\Composite.config add "AeontXsltExtensionsFunction" (if you have your code in App_Code) or like "ShopXsltExtensions" if you have your code in dll:

<Composite.Functions.Plugins.XslExtensionsProviderConfiguration>
    <XslExtensionProviders>
      <add name="ConfigurationBasedXslExtensionsProvider" type="Composite.Plugins.Functions.XslExtensionsProviders.ConfigBasedXslExtensionsProvider.ConfigBasedXslExtensionsProvider">
        <xslExtensions>
		<add name="#AeontXsltExtensionsFunction" type="Aeont.C1.Library.XsltExtensionsFacade, App_Code" />
		<add name="#ShopXsltExtensions" type="Shop.ShopXsltExtensions, Shop" />

 than add it:  xmlns:s="#ShopXsltExtensions" and use same way.

I've checked your xslt.. you have to re-done it a bit in order to work with C1.. first of all - sql - create sql function - http://docs.composite.net/C1/XSLT/SQLFunctions.aspx and use it's output OR if it's something complex - create C# function, get your data from sql here and via function call in XSLT function use its data.