XsltDb Integration

Introduction

Integration here is all the following:
  • Loading data from external sources.
  • Acting as external source for others.
  • Loading/Saving data from/to files.

Loading data from external sources

XSLT itself provides us with document() function that allows us to read xml data from http sources.

Example. Getting list of currencies from www.xignite.com. The service offer the following url for the list of currencies http://www.xignite.com/xCurrencies.asmx/ListCurrencies. First, review the xml it returns to decide how to deal with it.

<pre>{{mdo:text(document('http://www.xignite.com/xCurrencies.asmx/ListCurrencies')}}</pre>
We see the xml structure and also that it uses namespace. So we have to use it too. The following code creates a table with list of currencies

<xsl:variable name="curr" select="document('http://www.xignite.com/xCurrencies.asmx/ListCurrencies')" />

<table border="1" style="border-collapse:collapse;" xmlns:x="http://www.xignite.com/services/" >

  <tr><th>Symbol</th><th>Name</th><th>Countries</th></tr>

  <xsl:for-each select="$curr//x:CurrencyItem">
    <tr>
      <td>{{x:Symbol}}</td>
      <td>{{x:Name}}</td>
      <td>
        <xsl:for-each select=".//x:Country">
          {{x:Name}}<xsl:if test="position()!=last()">, </xsl:if>
        </xsl:for-each>
      </td>
    </tr>
  </xsl:for-each>

</table>
Look at the <table> tag. It has a namespace declaration to provide access to currency list as it returned with a namespace. If you want to remove namespace from HTML code of your page you have to use full from of xslt with xsl:stylesheet tag:

<xsl:stylesheet version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:msxsl="urn:schemas-microsoft-com:xslt"
   xmlns:x="http://www.xignite.com/services/"
   exclude-result-prefixes="msxsl mdo x"
   xmlns:mdo="urn:mdo"
>
  <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <xsl:variable name="curr" select="document('http://www.xignite.com/xCurrencies.asmx/ListCurrencies')" />
    <table border="1" style="border-collapse:collapse;">
      <tr><th>Symbol</th><th>Name</th><th>Countries</th></tr>
      <xsl:for-each select="$curr//x:CurrencyItem">
        <tr>
          <td>{{x:Symbol}}</td>
          <td>{{x:Name}}</td>
          <td>
            <xsl:for-each select=".//x:Country">
              {{x:Name}}<xsl:if test="position()!=last()">, </xsl:if>
            </xsl:for-each>
          </td>
        </tr>
      </xsl:for-each>
    </table>

  </xsl:template>
</xsl:stylesheet>
Look at the xsl:stylesheet element: First we need to declare namespace "x" and then exclude it from output by adding it to list of prefixes at exclude-result-prefixes attribute. This approach allows us to build clear HTML omitting any namespaces we don’t want to send to client.

Acting as external source for others

XsltDb has a special handler to let you call particular module without having to load page into the browser.
Example. Server date and time service with XsltDb

<root>
  <server-date>{{mdo:date('d')}}</server-date>
  <server-time>{{mdo:date('hh:mm:ss')}}</server-time>
</root>
After we created the module we can access it using the following URL

<<Your portal root address>>/DesktopModules/XsltDb/ws.aspx?mod=<<Module ID>>

What I have at my environment:
ws.PNG

Loading/Saving data from/to files.

Topic is to be created.

Last edited May 12, 2010 at 4:58 AM by findy, version 3

Comments

No comments yet.