Post date: Mar 27, 2012 1:47:33 PM
Background
QBO offers standard XSLT plugins, which let you access C# functionality from XSLT documents. At the time if this blog post, these include
qbo.Application.Utilities
XsltData.cs
XsltFormatting.cs
qbo.Security.Utilities
XstlSecurity.cs
To access these plugins, you must:
Ensure your QBO 3 instance includes Config/XsltExtension.config,
Alias the appropriate namespace(s) in your XSLT document,
Reference these function with their namespace alias
For example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:data="urn:qbo3-data"
xmlns:format="urn:qbo3-formatting"
xmlns:security="urn:qbo3-security"
exclude-result-prefixes="msxsl format data security"
>
...
<xsl:if test="security:isInRole('SecurityAdmin')">
<xsl:for-each select="data:invoke('Collection', 'Search', 'SourceObject=Person'))//CollectionItem"">
<li class="menu" onclick="...">
<xsl:text>Join Team </xsl:text>
<xsl:value-of select="format:pascalFromLabel(Collection)"/>
</li>
</xsl:for-each>
</xsl:if>
</xsl:stylesheet>
Formatting (urn:qbo3-formatting)
This class includes methods to assist with simple formatting, including some neat date stuff. For a full list, please review the class itself. Some teaser examples:
pascalFromLabel(string): turns ImportFileTemplate into Import File Template
lastPart(input, delimiter): turns /Templates/Folder/File.ext into File.ext
toDate(string): accepts today | yesterday | tomorrow | first | last (e.g. toDate('first') returns the first of the current month)
dateAdd('today', 'd', 3): returns three days from today
Data (urn:qbo3-data)
This is the most powerful XSLT extension object, as it allows you to invoke any DbMethod or DbStatement in any class. It has just one method:
invoke(className, method, queryString)
where:
className is the name of the class (table) you wish to invoke (e.g. 'Valuation', 'Collection', 'Message', etc.)
method is the name of the method you wish to invoke
queryString is a query string of parameters you wish to pass to the method
This is roughly equivalent to QBO 2.0's ExecuteProcedure method, with these notable enhancements:
The queryString parameter makes passing parameters much easier than constructing an XmlNode as an xsl:variable,
This can call actual class methods, not just data-related statements, and
It leverages the full QBO security model
Security (urn:qbo3-security)
This method provide three basic methods:
bool isInRole(role): checks to see if the current user is a member of role
bool hasPermission(function): checks to see if the current user has permission to 'function'
string userName(): user name of the current user
long userID(): user ID (PersonID) of the current user
XmlNode user(): returns the current user's Person record