Spindoctor API

The Spindoctor Behavioral Targeting API connects the business logic to the code. Use the API to select targeted content or the current visitor profile.

Access the API from XSLT

You can access the API from within your XSLT using SpindoctorLibrary:[API-Function].
The API functions return XML nodes.

This is a sample how to start your Xslt. Notice 2 important items:
Line 15 - Registering SpindoctorLibrary and Line 16 - Excluding SpindoctorLibrary from the result prefixes.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library" 
  xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" 
  xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" 
  xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" 
  xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" 
  xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" 
  xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
  xmlns:tagsLib="urn:tagsLib" 
  xmlns:SpindoctorLibrary="urn:SpindoctorLibrary"  
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib SpindoctorLibrary ">

 

Current visitor profile

You can access the current visitor profile using the CurrentVisitorProfile() method.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library" 
  xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" 
  xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" 
  xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" 
  xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" 
  xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" 
  xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
  xmlns:tagsLib="urn:tagsLib" 
  xmlns:SpindoctorLibrary="urn:SpindoctorLibrary" 
	exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib SpindoctorLibrary">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">
<xsl:variable name="profile" select="SpindoctorLibrary:CurrentVisitorProfile()"/>

<div class="hotspot">
  <h4>Profiling results</h4>
  <h3>Geo trace</h3>
  <ul>
	  <li>Country: <xsl:value-of select="$profile//Location/@Country" /> (<xsl:value-of select="$profile//Location/@CountryCode" />)</li>
	  <li>Region: <xsl:value-of select="$profile//Location/@Region" /></li>
	  <li>City: <xsl:value-of select="$profile//Location/@City" /> (approx.)</li>
  </ul>
  <h3>Profiling</h3>
	<p>
    <ul>  
	    <xsl:for-each select="$profile//ProfileAttribute">
		    <li><xsl:value-of select="@Name" /><ul>
			    <xsl:for-each select="./Component">    
				    <li><xsl:value-of select="@Name" /> (<xsl:value-of select="@Percentage" />%)</li>  
			    </xsl:for-each>
		    </ul></li>  
	    </xsl:for-each>
    </ul>
  </p>
  <h3>Segmentation</h3>
	<p>
    <ul>  
	    <xsl:for-each select="$profile//Segment[@IsInSegment='True']">
		    <li><xsl:value-of select="@Name" /></li>  
	    </xsl:for-each>
    </ul>
  </p>
  <h3>Unique Id</h3>
  <p>
    <xsl:value-of select="$profile//VisitorProfile/@Id" />
  </p>
</div>
</xsl:template>

</xsl:stylesheet>

 

Targeted content from a content selector

You can access the output of a content selector using two different methods:
SelectNodes(string contentSelectorName) and SelectSingleNode(string contentSelectorName).

This example shows how to use SelectSingleNode:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library" 
  xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" 
  xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" 
  xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" 
  xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" 
  xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" 
  xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
  xmlns:tagsLib="urn:tagsLib" 
  xmlns:SpindoctorLibrary="urn:SpindoctorLibrary"  
	exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib SpindoctorLibrary">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<xsl:variable name="cta" select="SpindoctorLibrary:SelectSingleNode('sdSelectHomepageCTA')"/>
<xsl:variable name="profile" select="SpindoctorLibrary:CurrentVisitorProfile()"/>
  
<div class="homepageInfo">
  <h2>
    <xsl:choose>
      <xsl:when test="$profile//Location/@Message = 'Not found'">
        <xsl:value-of select="umbraco.library:Replace($cta/bigTitle, '{0}', 'LocalhostCity')" disable-output-escaping="yes" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="umbraco.library:Replace($cta/bigTitle, '{0}', $profile//Location/@City)" disable-output-escaping="yes" />
      </xsl:otherwise>
    </xsl:choose>
  </h2>
  <p>
    <xsl:value-of select="$cta/introText" disable-output-escaping="yes" />
  </p>
  <a class="ui-btn ui-btn-big" href="/our-collection.aspx">
    <xsl:value-of select="$cta/buttonText" disable-output-escaping="yes" />
  </a>
</div>
</xsl:template>

</xsl:stylesheet>

 

Use SelectNodes to return a list of nodes instead of a single node: 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library" 
  xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" 
  xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" 
  xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" 
  xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" 
  xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" 
  xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
  xmlns:tagsLib="urn:tagsLib" 
  xmlns:SpindoctorLibrary="urn:SpindoctorLibrary"  
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib SpindoctorLibrary ">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<xsl:variable name="paintings" select="SpindoctorLibrary:SelectNodes('sdMatchProductHomepage')"/>

<div id="slider">
    <div id="imageSlider">
      <xsl:for-each select="$paintings">
        <div class="imageSlide">
          <div class="imageSliderImage">
            <img src="{mainImage}" width="420" height="307" />
          </div>
        </div>
      </xsl:for-each>
   </div>
</div>
</xsl:template>

</xsl:stylesheet>