Developer forum

Forum » Templates » Ecom group number in XML

Ecom group number in XML

Martin Gammelholm
Reply

Hi,

I want to display images in my menu based on the group number, but I can't seem to get the number out in my XSLT.

Testing with: 

<textarea>
<xsl:copy-of select="." />
</textarea>

Any clues?
Attaching the XSLT.

BR
Martin


 

 
 

 

 

 


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

The group data (incl. number) is not directly available in the ecom navigation xml, but if you dare – and I know you do – you can use a piece of c# code in your xslt to get the actual group:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="urn:my-scripts">
  
  <!-- @see http://msdn.microsoft.com/en-us/library/533texsx(v=vs.110).aspx -->
  <msxsl:script language="C#" implements-prefix="user">
    <msxsl:assembly name="Dynamicweb" />
    <![CDATA[
/*
 * Get group number from group id in query string
 */
public string GetGroupName(string url){
  var match = System.Text.RegularExpressions.Regex.Match(url, @"GroupID=(?<GroupID>[^&]+)");
  if (match.Success) {
    var groupID = match.Groups["GroupID"].Value;
    var group = Dynamicweb.eCommerce.Products.Group.GetGroupByID(groupID);
    if (group != null) {
      return group.Number;
    }
  }
  return "";
}
]]>
  </msxsl:script>

  …

  <xsl:template match="/NavigationTree//Page[@MenuText != '']">
    …
    <xsl:variable name="groupName" select="user:GetGroupName(@Href)"/>
      <xsl:if test="$groupName">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="$groupName"/>
        <xsl:text>]</xsl:text>
      </xsl:if>
      …
  </xsl:template>
</xsl:stylesheet>

I'm not sure about any performance issues, but it's nice to be able to use real code in your xslt templates.

Best regards,
Mikkel

 

 


 

 

 

 

 

   

 

Votes for this answer: 1
 
Martin Gammelholm
Reply

Hi Mikkel!

Thanks, it really works ;)

I'm affraid about performance tho. Wouldn't this require the IIS to generate an DLL for each item?

 

BR
Martin


 

 

 

 

 

 

 

You must be logged in to post in the forum