The data-access namespace is an extension object that is passed the XSLT transform. It allows the transform to have access to the .NET DataServices layer, and allows any installed .NET data provider to be used to read and write data.
Several xslt examples of the data-access namespace in action can be found in
XsltMarkupPlugin data-access namespace Examples.
The data-access namespace made accessable in an xslt transform by declaring the following namespace
xmlns:data="http://daisley-harrison.com/namespaces/screwturnwiki/xsltmarkupplugin/data-access"All open connections are automatically closed at the end of page processing.
ClearExceptions
Clears any exceptions on the specified connection
usage example:
<xsl:variable name="not-used" select="data:ClearExceptions($connection)"/>
ClearParameters
Clears all parameters currently set on the specified connection.
usage example:
<xsl:variable name="not-used" select="data:ClearParameters($connection)"/>
Close
Closes the current connection.
usage example:
<xsl:variable name="not-used" select="data:Close($connection)"/>
CloseAll
Closes all open connections.
This is also called automatically at the end of page processing.
usage example:
<xsl:variable name="not-used" select="data:CloseAll()"/>
ExecuteCommand¶
Executes a command on the specified data connection.
usage example:
<xsl:variable name="number-of-rows-affected" select="data:ExecuteCommand($connection, "DELETE FROM PARTS WHERE PARTID=5")"/>
HasException
Returns true if the connection has exceptions on it. Note HasException will continue to return true, until a call to ClearExceptions is made.
usage example:
<xsl:if text="data:HasExceptions($connection)">
...perform some exception handling here...
</xsl:if>
OpenConnection
Opens a new connection to a database through a data provider.
The
OpenConnection function returns a unqiue string that is used to identify the connection in all other function calls in the data-access namespace.
If the connection fails to open, the string returned is "
ERROR" and subsequent calls to HasExceptions will return true.
usage example:
<xsl:variable name="connection" select="data:OpenConnection('System.Data.SqlClient','Data Source=(local);Initial Catalog=AdventureWorksBM;Integrated Security=yes')"/>
ORA connection string can be configured in the web.config file and used as follows:
<xsl:variable name="connection" select="data:OpenConnection('System.Data.SqlClient','PreconfiguredConnectionStringName')"/>
OpenNamedConnection
Opens a new connection expicitly named connection to a database through a data provider.
The
OpenNamedConnection function returns the name of the connection in a string that is used to identify the connection in all other function calls in the data-access namespace. A named connection can be shared by all markup on the same page.
Note that connection names MUST be unique for all connections opened on a page.
It is good pratice to call close collections when your markup is finished. All connections are automatically closed at the end of page processing.
If the connection fails to open, the string returned is "
ERROR" and subsequent calls to HasExceptions will return true.
usage example:
<xsl:variable name="connection" select="data:OpenNamedConnection('System.Data.SqlClient','MyConnectionName', 'Data Source=(local);Initial Catalog=AdventureWorksBM;Integrated Security=yes')"/>
ORA connection string can be configured in the web.config file and used as follows:
<xsl:variable name="connection" select="data:OpenConnection('System.Data.SqlClient','PreconfiguredConnectionStringName')"/>
Providers
Returns the list of .NET data providers that are currently installed on your server.
usage example:
<xsl:variable name="list-of-providers" select="data:Providers()"/>
Query
Performs a query that returns a result-set on the specified connection
usage example:
<xsl:variable name="list-of-parts-and-bins" select="data:Query($connection, 'SELECT * FROM PART LEFT OUTER JOIN BIN ON BIN.BINID = PART.BINID WHERE PARTID = 5')"/>
<!-- now format the result-set into a table -->
<table>
<tr>
<xsl:for-each select="$list-of-parts-and-bins/result-set/schema/column">
<th>
<xsl:value-of select="@name"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="$list-of-parts-and-bins/result-set/rows/row">
<tr>
<xsl:for-each select="column">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
ScalarQuery
Performs a query the returns a scalor value on the specified connection
usage example:
<xsl:variable name="description" select="data:Query($connection, 'SELECT DESCRIPTION FROM PART WHERE PARTID = 5')"/>
SetParameter
Sets a parameter name and value on the specified connection, for use in subsequence queries or commands.
usage example:
<xsl:variable name="not-used" select="data:SetParameter($connection, '@PARTID','INT16', '42')"/>
<xsl:variable name="list-of-parts-and-bins" select="data:Query($connection, 'SELECT * FROM PART LEFT OUTER JOIN BIN ON BIN.BINID = PART.BINID WHERE PARTID = @PARTID')"/>
GetParameter
Gets the value of a parameter set on the specified connection.
usage example:
<xsl:variable name="parameter-value" select="data:SetParameter($connection, '@PARTID')"/>
Known Issues and Feature Requests¶