Examples overview
To make reading the XSLT samples easier the following template is included in most of the examples
ExamplesHelper. It is used for formatting the output of calls to the data-access namespace.
DataProvidersMarkup.xslt
This transform outputs the list of available .NET DataService DataProviders available for you to use.
<?xml version="1.0" encoding="utf-8"?>
<?markup
namespace DataProviders;
syntax wiki;
author "Aaron G. Daisley-Harrison";
copyright "© Copyright 2009 - Daisley-Harrison Software";
support-url http://support.daisley-harrison.com/wiki/Support.XsltMarkupPlugin.ashx;
?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:data="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/data-access"
xmlns:context="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/wiki-context"
xmlns:http="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/http-context">
<xsl:output method="html" indent="yes"/>
<xsl:param name="match-number"/>
<xsl:param name="base-uri"/>
<xsl:param name="unnamed-parameter-0"/>
<xsl:param name="all-parameters"/>
<xsl:include href="ExampleHelpers.xslt"/>
<xsl:template match="/">
<h1>DataProviders</h1>
<table>
<tr>
<th colspan="2">
data:Providers()
</th>
</tr>
<xsl:for-each select="data:Providers()">
<tr>
<th>
<xsl:value-of select="position()"/>
</th>
<td>
<xsl:call-template name="show-node-as-table">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
DisplaySQLTableMarkup.xslt
This transform reads all of the data from an SQL Server table and displays it as a table.
<?xml version="1.0" encoding="utf-8"?>
<?markup
namespace DisplaySQLTable;
formatting-phase dynamic;
syntax wiki;
author "Aaron G. Daisley-Harrison";
copyright "© Copyright 2009 - Daisley-Harrison Software";
support-url http://support.daisley-harrison.com/wiki/Support.XsltMarkupPlugin.ashx;
usage "{DisplaySQLTable: table-name [ | as-xml=yes ] }";
description "Displays an entire sql table from the AdventureWorksBM database";
?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:data="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/data-access"
xmlns:context="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/wiki-context"
xmlns:http="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/http-context">
<xsl:output method="html" indent="yes"/>
<xsl:param name="match-number"/>
<xsl:param name="base-uri"/>
<xsl:param name="unnamed-parameter-0"/>
<xsl:param name="as-table">yes</xsl:param>
<xsl:param name="as-xml">no</xsl:param>
<xsl:param name="all-parameters"/>
<xsl:include href="ExampleHelpers.xslt"/>
<xsl:variable name="tableName" select="$unnamed-parameter-0"/>
<xsl:template match="/">
<h1>DisplaySQLTable Markup Example</h1>
<xsl:variable name="connection" select="data:OpenConnection('System.Data.SqlClient','Data Source=(local);Initial Catalog=AdventureWorksBM;Integrated Security=yes')"/>
<xsl:if test="data:HasExceptions($connection)">
<h2 style="color:red">Data Access Connection Errors</h2>
<xsl:call-template name="show-node-as-table">
<xsl:with-param name="node" select="data:Exceptions($connection)"/>
</xsl:call-template>
</xsl:if>
<xsl:variable name="table-query">SELECT * FROM <xsl:value-of select="$tableName"/></xsl:variable>
<xsl:if test="$as-xml='yes'">
<xsl:call-template name="show-node-as-xml">
<xsl:with-param name="node" select="data:Query($connection, $table-query)"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$as-table='yes'">
<xsl:call-template name="show-result-sets-as-tables">
<xsl:with-param name="title">
<xsl:value-of select="$tableName"/> Table Using <xsl:value-of select="$table-query"/>
</xsl:with-param>
<xsl:with-param name="result-sets" select="data:Query($connection, $table-query)"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="data:HasExceptions($connection)">
<h2 style="color:red">Data Access Errors</h2>
<xsl:call-template name="show-node-as-table">
<xsl:with-param name="node" select="data:Exceptions($connection)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
DisplaySQLTableRowMarkup.xslt
<?xml version="1.0" encoding="utf-8"?>
<?markup
namespace DisplaySQLTableRow;
formatting-phase dynamic;
syntax wiki;
author "Aaron G. Daisley-Harrison";
copyright "© Copyright 2009 - Daisley-Harrison Software";
support-url http://support.daisley-harrison.com/wiki/Support.XsltMarkupPlugin.ashx;
usage "{DisplaySQLTableRow: {table-name | table=table-name} | id-column = column-name | id = value [ | as-xml=yes ] }";
example "{DisplaySQLTableRow: Part | id-column = Part_ID | id = 1010 }";
description " Displays one sql row from the AdventureWorksBM database";
?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:data="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/data-access"
xmlns:context="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/wiki-context"
xmlns:http="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/http-context">
<xsl:output method="html" indent="yes"/>
<xsl:param name="match-number"/>
<xsl:param name="base-uri"/>
<xsl:param name="unnamed-parameter-0"/>
<xsl:param name="table"/>
<xsl:param name="id-column"/>
<xsl:param name="id"/>
<xsl:param name="as-table">yes</xsl:param>
<xsl:param name="as-xml">no</xsl:param>
<xsl:param name="all-parameters"/>
<xsl:include href="ExampleHelpers.xslt"/>
<!-- this choose statement allows the user to choose between
* having first unnamed parameter to be the table name
or * explicitly naming the table parameter -->
<xsl:variable name="tableName">
<xsl:choose>
<xsl:when test="$table">
<xsl:value-of select="$table"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$unnamed-parameter-0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template match="/">
<h1>DisplaySQLTableRow Markup Example</h1>
<xsl:if test="$tableName=''">
<p style="color: red">MARKUP PARAMETER table-name is missing!</p>
</xsl:if>
<xsl:if test="$id-column=''">
<p style="color: red">MARKUP PARAMETER id-column is missing!</p>
</xsl:if>
<xsl:if test="$id=''">
<p style="color: red">PARAMETER id-column is missing!</p>
</xsl:if>
<xsl:variable name="connection" select="data:OpenConnection('System.Data.SqlClient','Data Source=(local);Initial Catalog=AdventureWorksBM;Integrated Security=yes')"/>
<xsl:if test="data:HasExceptions($connection)">
<h2 style="color:red">Data Access Connection Errors</h2>
<xsl:for-each select="data:Exceptions($connection)">
<xsl:call-template name="show-node-as-table">
<xsl:with-param name="title">AdventureWorksBM Parts</xsl:with-param>
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
<xsl:variable name="row-query">SELECT * FROM <xsl:value-of select="$tableName"/> WHERE <xsl:value-of select="$id-column"/>=@id_value</xsl:variable>
<xsl:variable name="not-used" select="data:SetParameter($connection,'@id_value','string', $id)"/>
<xsl:if test="$as-xml='yes'">
<xsl:call-template name="show-node-as-xml">
<xsl:with-param name="node" select="data:Query($connection, $row-query)"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$as-table='yes'">
<xsl:call-template name="show-result-sets-as-tables">
<xsl:with-param name="title">
<xsl:value-of select="$tableName"/> Row using <xsl:value-of select="$row-query"/>
</xsl:with-param>
<xsl:with-param name="result-sets" select="data:Query($connection, $row-query)"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="data:HasExceptions($connection)">
<h2 style="color:red">Data Access Errors</h2>
<xsl:for-each select="data:Exceptions($connection)">
<xsl:call-template name="show-node-as-table">
<xsl:with-param name="title">AdventureWorksBM Parts</xsl:with-param>
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>