[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

xquery extension function for xslt

Andrew Welch andrew.j.welch at gmail.com
Tue Sep 4 19:00:42 PDT 2007


  xquery extension function for xslt
I've knocked together a quick n dirty xquery extension function for
use with eXist and Saxon and included it in Kernow.

This sample XSLT calls the runQuery() extension passing in the uri for
eXist, the collection and the query to execute.  The function returns
a sequence of Strings (!) that can then be turned into nodesets using
saxon:parse() (which you wouldn't use if atomics are returned)  Below
it gets all <title> elements with String values start with with 'H',
from the 'mycol' collection:

<xsl:stylesheet version="2.0"
xmlns:k="net.sf.kernow.extensions.XQueryExtension"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="k saxon">

<xsl:param name="db-uri"
select="'xmldb:exist://localhost:8080/exist/xmlrpc/db'"
as="xs:string"/>

<xsl:param name="collection" select="'/mycol'" as="xs:string?"/>

<xsl:param name="query" as="xs:string">
  for $x in //title
  return $x[starts-with(., 'H')]
</xsl:param>


<xsl:template match="/" name="main">

	<xsl:variable name="input" select="k:runQuery($db-uri, $collection, $query)"/>

	<xsl:copy-of select="for $x in $input return saxon:parse($x)"/>
	
</xsl:template>

</xsl:stylesheet


To try it out use the Java Web Start version of Kernow from here:
http://kernowforsaxon.sourceforge.net/jws.html  (may require patience
as the jars download for the first time)

Then use the "Standalone" tab, clicking the auto button to select the
named template.

(obviously you'll need eXist installed too)

I know this is really basic but hopefully you get the idea...

-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/


Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.