Edit the Descriptor XSL file.Using your preferred text editor, edit the Descriptor XSL file and change the main template rule at the top to look like this:
<!-- ============================================== -->
<!-- Match the Solution -->
<!-- ============================================== -->
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$_usage">
<xsl:call-template name="usage"/>
</xsl:when>
<xsl:otherwise>
<!-- store query answer in a variable called answer -->
<xsl:variable name="answer">
<!-- Query for list of models on server -->
<tucanaDescriptor:query server="{$server}">
<![CDATA[
select $model from <@@server@@#> where
$model <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://tucana.org/tucana#Model>;
]]>
</tucanaDescriptor:query>
</xsl:variable>
<!-- Now apply the templates to the answer -->
<xsl:copy-of select="xalan:nodeset($answer)/*"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Several new concepts are introduced in this Descriptor as opposed to the Hello World Descriptor.
The <tucanaDescriptor:query> Tag
<!-- Query for list of models on server -->
<tucanaDescriptor:query server="{$server}">
<![CDATA[
select $model from <@@server@@> where
$model <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://tucana.org/tucana#Model>;
]]>
</tucanaDescriptor:query>
This tag is an extension to XSL allowing queries to be made to a Kowari database. See The <query> Tag section for more information.
In a text child of this tag (that is, between the open and closing tags) an iTQL command is placed. The query text is stored in a CDATA section so as to stop the XML parser having problems with the angle brackets surrounding resources. The use of the @@server@@
is a simple token replacement mechanism. Any time a piece to text is found surrounded by '@@' the Descriptor looks for the text as an attribute of the query tag and replaces it with that value.
In this case the text @@server@@
is replaced with the value of the server attribute {$server}
which is the server parameter passed to the Descriptor on invocation. The client using this Descriptor must supply a server parameter. This contract (the interface in software engineering terms) is specified in the RDF of the Descriptor.
Looking further down the modellist.xsl
file is the parameter section like this:
<!-- Other RDF snipped -->
<!-- Parameter 1 -->
<desc:hasParam xmlns:desc="http://tucana.org/descriptor#" xmlns="http://www.w3.org/1999/xhtml">
<desc:Param>
<desc:name>server</desc:name>
<desc:type>String</desc:type>
<desc:required>Yes</desc:required>
<desc:description>The server to get a model list from</desc:description>
</desc:Param>
</desc:hasParam>
This RDF reflects the information the developer entered into the Descriptor wizard. The Descriptor code checks for parameters and reports any violations such as parameters not present or of the wrong type.
Once the interface is decided, you can change the logic of the XSL file (that is, the rules) without needing to redeploy the Descriptor. This means that Descriptors can be developed interactively. For example, a developer can be editing a Descriptor XSL file, make a change, save it, and invoke the Descriptor for immediate results. However, if any of the parameters change, then the Descriptor must be redeployed.
Note - Descriptors are cached by Kowari. If you change a Descriptor, then the cache must be cleared. This is available as a task from the Descriptor Management page.
The <tucanaDescriptor:query>
tag is surrounded by a <xsl:variable>
tag that stores the results of the query in the variable answer
. This is because the raw XML returned from an iTQL command is not very useful on its own. If you want to work with the raw XML directly, then you should work with the Java API interface to Kowari.
The tag <xsl:copy-of select="xalan:nodeset($answer)/*"/>
is very useful for debugging. It copies the response from the Kowari (that is, the raw XML) to the output. This is useful when working with new Descriptors where you do not know exactly what their output looks like.
Note - Future versions of Descriptors will also declare an XML Schema of the results they produce.
At this stage, it is advisable to temporarily jump to the next step and invoke the Descriptor as is. You should see a raw XML response something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<answer xmlns="http://tucana.org/tql#">
<query>
<variables>
<model/>
</variables>
<solution><model resource="rmi://mysite.com/server1#"/></solution>
<solution><model resource="rmi://mysite.com/server1#_"/></solution>
<solution><model resource="rmi://mysite.com/server1#descriptors"/></solution>
<solution><model resource="rmi://mysite.com/server1#customer"/></solution>
<solution><model resource="rmi://mysite.com/server1#sun"/></solution>
<solution><model resource="rmi://mysite.com/server1#nytimes"/></solution>
</query>
</answer>
If you do this, and then make further changes to your Descriptor (as you now will) you must clear the Descriptor cache. This is available as a task from the Descriptor Management page.
You now need to transform the above XML into an HTML list of the models. Writing a rule to match the <answer>
tag is a good way to write the HTML header and body tags. The <solution>
tag holds each solution to the query, like a row in a result set of an SQL query. First you must change the top most rule where you have the tag <xsl:copy-of select="xalan:nodeset($answer)/*"/>
to <xsl:apply-templates select="xalan:nodeset($answer)/*"/>
.
This applies the XSL template rules to the XML we received from Kowari. That is, its as if the raw XML was the input document to the XSL transformer. Now you need to write the two rules, one to match the answer and one to match the solution.
Answer Rule:
<!-- #################################################### -->
<!-- converts answer into an HTML Page -->
<!-- #################################################### -->
<xsl:template match="tucanaAnswer:answer">
<html>
<head>
<title>Kowari models</title>
</head>
<body>
List of models on server <xsl:value-of select="$server"/>
<ol>
<xsl:apply-templates/>
</ol>
</body>
</html>
</xsl:template>
This matches with an answer, writes out an HTML header and body and starts an ordered list, then applies the rest of the rules before closing the ordered list and closing all the HTML tags.
Solution Rule:
<!-- ########################################################## -->
<!-- converts solution into an HTML List Element -->
<!-- ########################################################## -->
<xsl:template match="tucanaAnswer:solution">
<li><xsl:value-of select="tucanaAnswer:model/@resource"/></li>
</xsl:template>
This takes a solution and inserts the resource attribute of the <tucanaAnswer:model>
tag (refer to the raw XML response if this is unclear) into a list element tag <li>
. This effectively adds the Model URI to the HTML list.
Once you have entered both rules save the file again. You might want to check that the file is valid XML using a tool such as xmllint.