PHP Code Samples
In this example we show you how you can call the View My Account (VMA) Web service from PHP environment and then direct Talis Keystone to perform an XSL Transformation on the results. You can download the source code (zip) from here.
In order to run these scripts, you need to install PHP and Apache HTTP Server. The actual request to the Web service is made using CURL (a PHP library), which you must also download and configure.
The following snippet of PHP will use CURL to request Talis Keystone's REST service for a borrower whose Barcode is 12593486, posted to a Talis Keystone View My Account REST endpoint on a machine called sandbox.talis.com (Talis Keystone sandbox). At the heart of this piece of code is the construction of the serviceURL, which has been covered in the Getting Started with Talis Keystone tutorial.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<!--
THIS FOLLOWING SNIPPET OF PHP WILL USE CURL TO REQUEST TALIS KEYSTONE'S REST SERVICE FOR BORROWER 12593486.
-->
<?php
$detailsObtained = false;
$borrowerId = "12593486";
$serviceURL = "http://sandbox.talis.com/TalisKeystone/ViewMyAccountRESTService?Barcode=".$borrowerId.
"&Summary&AccessURL&FiscalAccount&LoanedItems&ReservedItems&RequestedItems&BookedItems";
$cobj=curl_init($serviceURL);
curl_setopt($cobj,CURLOPT_RETURNTRANSFER,1);
$response=curl_exec($cobj);
curl_close($cobj);
if ($response)
{
$detailsObtained = true;
}
?>
<!-- DISPLAY THE RESULTS OF THE REST CALL -->
<?php
if ($detailsObtained)
{
echo($response);
}
?>
</body>
</html>
The above request will return the result in raw xml, which is not very elegant. Therefore, we can utilise the xsl transformation capability of the API to provide html output more suitable for end user consumption.
To apply xsl transformation to the raw result, we create a simple xslt script (MyLibraryAccount.xsl):
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/TalisKeystoneResponse/ViewMyAccountResponse">
<div id="browsetabs">
<ul>
<li>
<a>Summary</a>
</li>
</ul>
</div>
<p>Hello
<span class="boldtext">
<xsl:value-of select="userName"/>
</span>
</p>
<table align="left" width="300" border="0" cellspacing="0" cellpadding="3" class="summary">
<tr>
<td class="boldtext">Charges:</td>
<td>
£<xsl:value-of select="UserFiscalAccount/AccountBalance/FormatedMonetaryValue"/>
</td>
</tr>
<tr>
<td class="boldtext">Loans:</td>
<td>
<xsl:value-of select="LoanedItemsCountValue"/>
</td>
</tr>
<tr>
<td class="boldtext">Reservations:</td>
<td>
<xsl:value-of select="ReservedItemsCountValue"/>
</td>
</tr>
<tr>
<td class="boldtext">Requests:</td>
<td>
<xsl:value-of select="RequestedItemsCountValue"/>
</td>
</tr>
<tr>
<td colspan="2">
<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="UserAccessURL"/>
</xsl:attribute>My Library Account
</a>
</td>
</tr>
</table>
<br/>
<xsl:if test="UserFiscalAccount">
<xsl:if test="UserFiscalAccount/AccountBalance/MonetaryValue > 0">
<div id="browsetabs">
<ul>
<li>
<a>Charges</a>
</li>
</ul>
</div>
<table align="left" width="300" border="0" cellspacing="0" cellpadding="3" class="summary">
<tr>
<td class="boldtext">Type</td>
<td class="boldtext">Amount</td>
<td class="boldtext">Details</td>
</tr>
<xsl:for-each select="UserFiscalAccount/AccountDetails">
<tr>
<td valign="top" align="left">
<xsl:value-of select="FiscalTransactionInformation/FiscalTransactionType"/>
</td>
<td valign="top" align="left">
£<xsl:value-of select="FiscalTransactionInformation/Amount/FormatedMonetaryValue"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="FiscalTransactionInformation/ItemDetails"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
</xsl:if>
<xsl:if test="UserTransaction/LoanedItem">
<div id="browsetabs">
<ul>
<li>
<a>Loans</a>
</li>
</ul>
</div>
<table align="left" width="300" border="0" cellspacing="0" cellpadding="3" class="summary">
<tr>
<td class="boldtext">Title</td>
<td class="boldtext">Author</td>
<td class="boldtext">Due Date</td>
<td class="boldtext">Potential Charge</td>
</tr>
<xsl:for-each select="UserTransaction/LoanedItem">
<tr>
<td valign="top" align="left">
<xsl:value-of select="BibliographicDescription/Title"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="BibliographicDescription/Author"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="DateDue"/>
</td>
<td valign="top" align="left">
£<xsl:value-of select="Amount/FormatedMonetaryValue"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
<br/>
<xsl:if test="UserTransaction/ReservedItem">
<div id="browsetabs">
<ul>
<li>
<a>Reservations</a>
</li>
</ul>
</div>
<table align="left" width="300" border="0" cellspacing="0" cellpadding="3" class="summary">
<tr>
<td class="boldtext">Title</td>
<td class="boldtext">Author</td>
<td class="boldtext">Request Date</td>
<td class="boldtext">Need Before Date</td>
</tr>
<xsl:for-each select="UserTransaction/ReservedItem">
<tr>
<td valign="top" align="left">
<xsl:value-of select="BibliographicDescription/Title"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="BibliographicDescription/Author"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="DateOfUserRequest"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="NeedBeforeDate"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
<xsl:if test="UserTransaction/RequestedItem">
<div id="browsetabs">
<ul>
<li>
<a>Requests</a>
</li>
</ul>
</div>
<table align="left" width="300" border="0" cellspacing="0" cellpadding="3" class="summary">
<tr>
<td class="boldtext">Title</td>
<td class="boldtext">Author</td>
<td class="boldtext">Request Date</td>
<td class="boldtext">Need Before Date</td>
</tr>
<xsl:for-each select="UserTransaction/RequestedItem">
<tr>
<td valign="top" align="left">
<xsl:value-of select="BibliographicDescription/Title"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="BibliographicDescription/Author"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="DateOfUserRequest"/>
</td>
<td valign="top" align="left">
<xsl:value-of select="NeedBeforeDate"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
<br/>
</xsl:template>
</xsl:stylesheet>
and the associated css file (MyLibraryAccount.css):
.boldtext{
font-weight: bold;
}
.summary{
margin: auto;
}
/* ======= Tab layout begins ========= */
#browsetabs{
background-color: White;
padding-top: 10px;
height: 21px;
clear: both;
line-height:20px;
margin: 0;
_margin-bottom: -1px; /* IE only */
}
#browsetabs ul{
list-style: none;
margin: 0 0 0 35px;
padding: 0px;
}
#browsetabs li{
margin: 0 auto;
padding: 0px;
float: left;
background-repeat: no-repeat;
background-position: right top;
}
#browsetabs a{
display: block;
background-repeat: no-repeat;
background-position: left top;
padding: 0px 19px 1px;
text-decoration: none;
font-weight: normal;
color: Black;
border-bottom: 1px solid Black;
}
#browsetabs li.current a{
background-repeat: no-repeat;
font-weight: bold;
padding: 0px 19px 2px;
border-bottom: none;
}
/* Tab layout ends */
You must save the above files (MyLibraryAccount.xsl and MyLibraryAccount.css) on to a web server, which the Talis Keystone server can access, and then use the service parameter uriStyle to specify the location of the xslt script in your PHP code. You must also include any css stylesheets used by the xslt script in the head section of the PHP page. So the final version of our PHP file (MyLibraryAccount.php) will look like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--LINK TO EXTERNAL STYLESHEET CALLED "MyLibraryAccount.css" -->
<link href="MyLibraryAccount.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!--
THIS FOLLOWING SNIPPET OF PHP WILL USE CURL TO REQUEST TALIS KEYSTONE'S REST SERVICE
AND PERFORM AN XSL TRANSFORMATION FOR BORROWER 12593486.
THE URL http://www.talis.com/keystone_toolkit/MyLibraryAccount.xsl
IS THE LOCATION OF THE XSL STYLESHEET ON A WEB SERVER WHICH THE TALIS KEYSTONE
SERVER HAS ACCESS TO.
THE SERVICE URL USES THE REST PARAMETER uriStyle WHICH SPECIFIES THE LOCATION OF THE XSL STYLESHEET.
WHEN THIS PARAMETER IS PRESENT TALIS KEYSTONE WILL PERFORM AN XSL TRANSFORMATION AND RETURN THE
RESULTS OVER HTTP.
-->
<?php
$detailsObtained = false;
$xslURI = "http://www.talis.com/keystone_toolkit/MyLibraryAccount.xsl";
$borrowerId = "12593486";
$serviceURL = "http://sandbox.talis.com/TalisKeystone/ViewMyAccountRESTService?Barcode=".$borrowerId.
"&Summary&AccessURL&FiscalAccount&LoanedItems&ReservedItems&RequestedItems&BookedItems&uriStyle=".$xslURI;
$cobj=curl_init($serviceURL);
curl_setopt($cobj,CURLOPT_RETURNTRANSFER,1);
$response=curl_exec($cobj);
curl_close($cobj);
if ($response)
{
$detailsObtained = true;
}
?>
<!-- AND THEN DISPLAY THE RESULTS OF THE TRANSFORMATION... -->
<?php
if ($detailsObtained)
{
echo($response);
}
?>
</body>
</html>
You can download the source code (zip) from here



JSP code samples
Hi could you let me know if there are any jsp code samples.
Thanks for your time, Iola
New JSP Toolkit for Talis Keystone added
Hi Iola,
I've created a JSP toolkit which you can download from here:
http://www.talis.com/tdn/keystone/downloads
I hope this helps, if you need anything else then please let me know.
Kind regards,
-Andy
Andy Latham
Programme Manager, Talis Keystone
Talis Information Limited
www.talis.com
ASP port
Hi,
I'm hoping there's some documentation knocking around to show how to access the API using classic ASP. We have no other option from here, and I'm trying to avoid my own error-prone porting.
Thanks