If you want to use a hash lookup to improve performance of the references
into File B, why not use keys?
What you are actually trying to do seems to be to evaluate the subquery
e.g. image[@name='title']/@path
against the nodes in the nodeset that you saved in your hashtable.
You can do that by extracting this node-set into a variable:
xsl:variable name="images" select="hashtable:get(...)"
Then constructing a new expression:
xsl:variable name="newquery" select="concat('$images/', $subquery)"
Then evaluating this:
xsl:variable name="result" select="saxon:evaluate($newquery)"
I don't really like this use of an external hashtable to circumvent XSLT's
restrictions on variables. It means you're working against the language,
rather than with it. I suspect that by using keys, you could get the
performance you need without resorting to an external hashtable.
Mike Kay
> I have two xml files (A and B) and one xsl file.
>
>
> File A
>
> <element>
> ...
> ...
> <queries>
> <query name="IMAGES" query="//images"/>
> <query name="TEXTS" query="//texts"/>
> </queries>
> ...
> ...
> ...
>
> <image x="0" y="0" width="200" height="50">
> <content queryName="IMAGES"
> subQuery="image[@name='title']/@path"/>
> <image>
>
> <image x="10" y="100" width="50" height="50">
> <content queryName="IMAGES"
> subQuery="image[@name='photo1']/@path"/>
> <image>
>
> <image x="200" y="200" width="50" height="50">
> <content queryName="IMAGES"
> subQuery="image[@name='photo2']/@path"/>
> <image>
>
> <text x="200" y="200">
> <content queryName="TEXTS"
> subQuery="text[@name='text2']/@value"/>
> <text>
>
> </element>
>
>
> File B
>
> <resources>
> <images>
> <image name="title" path="fondo.jpg"/>
> <image name="photo1" path="pop_up.jpg"/>
> <image name="photo2" path="logo_beca.jpg"/>
> </images>
> <texts>
> <text name="text1" value="is the text1"/>
> <text name="text2" value="is the text2"/>
> <text name="text3" value="is the text3"/>
> </texts>
> </resources>
>
> the xsl file process the file A and does querys (XPath)
> into file B.
>
> The problem is that if I have 100 images and 100 texts
> in my file A I have
> that access to file B (disk) 200 times and I want access only
> one time for
> Images and another time to texts to disk in order to increase
> the perform.
>
>
>
> With this template I make a hashtable with a
> (QueryName, Nodeset result)
> pairs.
> where the QueryPool is the hashtable.
>
> <xsl:template match="//queries/query">
> <xsl:choose>
> <xsl:when test="@value">
> <xsl:variable name="query" select="@value"/>
> <xsl:variable name="name" select="@name)"/>
> <xsl:for-each
> select="document('path_to_resources_file')">
> <xsl:variable name="result"
> select="saxon:evaluate($query)"/>
> <xsl:value-of
> select="QueriesPool:put($pool,$name, $result)"/>
> </xsl:for-each>
> </xsl:when>
> </xsl:choose>
> </xsl:template>
>
>
> And I try evaluate the subQueries for example
> image[@name ='photo1']/@path
> into a nodeSet that is saved in the hashtable with the key=IMAGES
> (QueriesPool:get($pool,'IMAGES'))
>
> How can I do this?
>
> the problem is that i don´t know evaluate a subQuery
> into a nodeset. is
> this possible?
>
>
> i´m sorry but my english isn´t very good.
>
> kind regards.
>
>
>
>
> -----Mensaje original-----
> De: Michael Kay [mailto:mhkay@...]
> Enviado el: lunes 23 de julio de 2001 18:40
> Para: 'SAXON XSL Discussion List'
> Asunto: RE: evaluate Xpath expresion into nodeset in Java extension
>
>
> SAXON XSL Discussion List - http://users.iclway.co.uk/mhkay/saxon/
>
> --------------------------- ListBot Sponsor --------------------------
> Start Your Own FREE Email List at http://www.listbot.com/links/joinlb
> ----------------------------------------------------------------------
>
> > how can i call saxon:evaluate() from my stylesheet to evaluate a
> > xPathExpresion into nodeSet contained into variable?
>
> For example:
>
> <xsl:variable name="x" select="string(//image[1])"
> <xsl:variable name="nodes" select="saxon:evaluate($x)"/>
>
> This evaluates the XPath expression contained as the string
> value of the
> selected <image> element in the source document.
>
> More details are on the extensions.html page.
>
> Mike Kay
>
> >
> > -----Mensaje original-----
> > De: Michael Kay [mailto:mhkay@...]
> > Enviado el: lunes 23 de julio de 2001 11:54
> > Para: 'SAXON XSL Discussion List'
> > Asunto: RE: evaluate Xpath expresion into nodeset in Java extension
> >
> >
> > SAXON XSL Discussion List - http://users.iclway.co.uk/mhkay/saxon/
> >
> > --------------------------- ListBot Sponsor
> --------------------------
> > Start Your Own FREE Email List at
> http://www.listbot.com/links/joinlb
> >
> ----------------------------------------------------------------------
> >
> > You've got an XPath expression in your source document, which
> > you want to
> > evaluate. You can do this by calling the saxon:evaluate()
> > extension function
> > from your stylesheet. You don't need to write any Java code
> > of your own.
> >
> > If you do want to evaluate XPath expressions from Java code,
> > see the "Using
> > XPath Expressions" section in the api-guide.html document.
> >
> > Please note, this list is closing! Please use the new list on
> > SourceForge,
> > see http://saxon.sourceforge.net/
> >
> > Mike Kay
> >
> > > -----Original Message-----
> > > From: Cesar Hernandez Fuente [mailto:chernandez@...]
> > > Sent: 23 July 2000 09:32
> > > To: saxon.xsl@...
> > > Subject: evaluate Xpath expresion into nodeset in Java extension
> > >
> > >
> > > SAXON XSL Discussion List - http://users.iclway.co.uk/mhkay/saxon/
> > >
> > > --------------------------- ListBot Sponsor
> > --------------------------
> > > Start Your Own FREE Email List at
> > http://www.listbot.com/links/joinlb
> > >
> >
> ----------------------------------------------------------------------
> > >
> > > hi
> > >
> > > i have this xml files
> > >
> > > the queries file
> > >
> > > <element>
> > > ...
> > > ...
> > > <queries>
> > > <query name="IMAGES" value="//image"/>
> > > <query name="TEXTS" value="//text"/>
> > > </queries>
> > > ...
> > > ...
> > > ...
> > >
> > > <text>
> > > <content queryName="TEXTS" subQuery="[@name='a']"/>
> > > <text>
> > > </elements>
> > >
> > >
> > > the resources file
> > >
> > > <resources>
> > > <images>
> > > <image name="a" file="fondo.jpg"/>
> > > <image name="b" file="pop_up.jpg"/>
> > > <image name="c" file="logo_beca.jpg"/>
> > > </images>
> > > <texts>
> > > <text name="a" value="Hello"/>
> > > <text name="b" value="Hi"/>
> > > <text name="c" value="Bye"/>
> > > </texts>
> > > </resources>
> > >
> > >
> > > and this XSL file that process the queries file.
> > >
> > > <?xml version="1.0" encoding="ISO-8859-1"?>
> > > <xsl:stylesheet version="1.0"
> > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > > xmlns:saxon="http://icl.com/saxon"
> > > extension-element-prefixes="saxon"
> > >
> > > xmlns:QueriesPool="/es.telenium.planeta.extensions.QueriesPool">
> > >
> > > <xsl:output omit-xml-declaration="yes"/>
> > >
> > > <xsl:variable name="pool" select="PoolConsultas:new()"/>
> > >
> > > <xsl:template match="/">
> > > <xsl:copy>
> > > <xsl:apply-templates/>
> > > </xsl:copy>
> > > </xsl:template>
> > >
> > > <xsl:template match="@*|*">
> > > <xsl:copy>
> > > <xsl:apply-templates select="@*"/>
> > > <xsl:apply-templates/>
> > > </xsl:copy>
> > > </xsl:template>
> > >
> > > <xsl:template match="//query">
> > > <xsl:choose>
> > > <xsl:when test="@value">
> > > <xsl:variable name="query" select="@value"/>
> > > <xsl:variable name="name" select="@name)"/>
> > > <xsl:for-each
> > > select="document('path_to_resources_file')">
> > > <xsl:variable name="result"
> > > select="saxon:evaluate($query)"/>
> > > <xsl:value-of
> > > select="QueriesPool:put($pool,$name, $result)"/>
> > > </xsl:for-each>
> > > </xsl:when>
> > > </xsl:choose>
> > > </xsl:template>
> > >
> > > <xsl:template match="//content">
> > > <xsl:element name="data">
> > > <xsl:attribute name="value">
> > > <xsl:variable name="subQuery" select="@subQuery"/>
> > > <xsl:variable name="queryName" select="@queryName"/>
> > > <xsl:value-of
> > > select="QueriesPool:evaluateExpresion($pool,$queryName,
> > > $subQuery)"/>
> > > </xsl:attribute>
> > > </xsl:element>
> > > </xsl:template>
> > > </xsl:stylesheet>
> > >
> > >
> > > QueriesPool CLASS
> > >
> > > public class PoolConsultas extends Hashtable
> > > {
> > > public Value evaluateExpresion(Context
> > > context, String queryName, String
> > > subQuery) throws
> > > org.xml.sax.SAXException
> > > {
> > > NodeSetValue node =
> > > (NodeSetValue)this.get(queryName);
> > >
> > > *************************
> > > i want put the node into the context for
> > > evaluate the subQuery
> > > ¿how can do this?
> > > *************************
> > >
> > > return Extensions.evaluate(contexto,subQuery);
> > > }
> > > }
> > >
> > > regards.
> > >
> > >
> > >
> >
> ______________________________________________________________________
> > > To unsubscribe, write to saxon.xsl-unsubscribe@...
> > >
> >
> >
> >
> ______________________________________________________________________
> > To unsubscribe, write to saxon.xsl-unsubscribe@...
> >
> >
> >
> ______________________________________________________________________
> > To unsubscribe, write to saxon.xsl-unsubscribe@...
> >
>
>
> ______________________________________________________________________
> To unsubscribe, write to saxon.xsl-unsubscribe@...
>
>
> ______________________________________________________________________
> To unsubscribe, write to saxon.xsl-unsubscribe@...
>
|