Hi,
You can do this by parsing the URL from an XSLT Extension function. It is not possibly the prettiest solution, but it works.
Step 1
In your web.config, locate the <xsltobjects node and add a line, as such:
HTML Code:
<xsltobjects defaultExtension="">
<extensions>
<clear />
<add name="receipt" namespace="urn:receipt" type="ReceiptXsltExtension, app_code" />
<add name="my" namespace="urn:my" type="my_CustomXSLTExtensions, app_code" />
</extensions>
</xsltobjects>
Step 2
At the top of your XmlPackage, edit the Namespace line to look like this:
HTML Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" xmlns:my="urn:my" exclude-result-prefixes="aspdnsf my">
Step 3
Add a new class file to the App_Code folder called 'my_CustomXSLTExtensions.cs'. In that class, add the following method:
Code:
public static int GetCurrentCategoryID()
{
try
{
string _url = HttpContext.Current.Request.Path;
if (_url.Contains("/c-"))
{
_url = _url.Replace("/c-", "");
return Convert.ToInt32(_url.Substring(0, _url.IndexOf("-")));
}
else if (_url.Contains("/p-"))
{
_url = _url.Replace("/p-", "");
return GetCategoryID(Convert.ToInt32(_url.Substring(0, _url.IndexOf("-"))));
}
else
{ return 0; }
}
catch { return 0; }
}
Step 4
Call your new function from within your XmlPackage like so:
HTML Code:
<xsl:value-of select="my:GetCurrentCategoryID()" />
Hope this helps!
EDIT:
In the above C# method, you will notice that if it is a standard Category page (ex. /c-...) then the CategoryID is parsed out and returned. If it is a standard Product page (ex. /p-...) the ProductID is parsed out and passed to a GetCategoryID method that simply queries the database to get the Category that this Product belongs to. If I recall correctly, this particular site the Products were mapped in one Category only, so this was sufficient. Obviously you can tailor the C# to your specific needs.
END EDIT: