You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by de...@de-schepper.be on 2002/06/18 14:35:02 UTC

nr of results && starting position

Hi,
 
Is it possible to manipulate the number of results that will be returned
by a query ?
 
What I want to do is the following:
 
xml-document contains following:
 
<mydoc>
<myitem id='1' timestamp='20020514123458568'>
    <elem1>content1</elem1>
    <elem2>content1</elem2>
    <elem3>content1</elem3>
</myitem>
<myitem id='2' timestamp='20020514123712235'>
    <elem1>content1</elem1>
    <elem2>content1</elem2>
    <elem3>content1</elem3>
</myitem>
<myitem id='3' timestamp='20020514124420645'>
    <elem1>content1</elem1>
    <elem2>content1</elem2>
    <elem3>content1</elem3>
</myitem>
<myitem id='4' timestamp='20020514125337067'>
    <elem1>content1</elem1>
    <elem2>content1</elem2>
    <elem3>content1</elem3>
</myitem>
<myitem id='5' timestamp='20020514125901348'>
    <elem1>content1</elem1>
    <elem2>content1</elem2>
    <elem3>content1</elem3>
</myitem>
</mydoc>
 
Now, I want to query this document for the next 2 items, starting with
item which timestamp='20020514124420645'
 
the query I am thinking of is something like this:
xindice xpath -c /db/mytestcol -q
"/mydoc/myitem[@timestamp='20020514124420645']"
 
but this will return only that one element
 
 
 
Guy

Re: nr of results && starting position

Posted by KOZLOV Roman <r-...@opencascade.com>.
Sorry again, of course it should be the following:

<xsl:template match="/">
    <xsl:apply-templates select="item" mode="base">
</xsl:template>

<xsl:template match="item" mode="base">
    <xsl:if test="self::node()[@name='theFirst']">
        <xsl:variable name="pos" select="position()"/>
        <xsl:variable name="lastpos" select="number($pos) + 100"/>
        <xsl:apply-templates select="item[((position() &lt; $lastpos) and
(position() &gt; $pos)) or (position() = $pos) ]" mode="iteration"/>
    </xsl:if>
</xsl:template>

<xsl:template match="item" mode="iteration">
    . . .
</xsl:template>

Roman

KOZLOV Roman wrote:

> Sorry, I've forgot the initial question conditions (identify item by some
> attribute):
>
> <xsl:template match="/">
>     <xsl:apply-templates select="item[@name='theFirst']" mode="base">
>         <xsl:with-param name="pos" select="39"/>
>     </xsl:applyl-templates>
> </xsl:template>
>
> <xsl:template match="item" mode="base">
>     <xsl:param name="pos"/>
>     <xsl:variable name="lastpos" select="number($pos) + 100"/>
>     <xsl:apply-templates select="item[((position() &lt; $lastpos) and
> (position() &gt; $pos)) or (position() = $pos) ]" mode="iteration"/>
> </xsl:template>
>
> <xsl:template match="item" mode="iteration">
>     . . .
> </xsl:template>
>
> KOZLOV Roman wrote:
>
> > Try the following construction:
> >
> > <xsl:template match="/">
> >     <xsl:call-template name="base">
> >         <xsl:with-param name="pos" select="39"/>
> >     </xsl:call-template>
> > </xsl:template>
> >
> > <xsl:template name="base">
> >     <xsl:param name="pos"/>
> >     <xsl:variable name="lastpos" select="number($pos) + 100"/>
> >     <xsl:apply-templates select="item[((position() &lt; $lastpos) and
> > (position() &gt; $pos)) or (position() = $pos) ]" mode="iteration"/>
> > </xsl:template>
> >
> > <xsl:template match="item" mode="iteration">
> >     . . .
> > </xsl:template>
> >
> > Best regards,
> > Roman
> >
> > Guy De Schepper wrote:
> >
> > > ok, this query will indeed do the job for this example, but what about
> > > large documents / collections ?let's say the document contains 10000
> > > items and I want to display them with 100 at a time.for each page
> > > (which will contain 100 items) I have to launch 100 queries !
> > >
> > >      -----Original Message-----
> > >      From: Jeff Greif [mailto:jgreif@alumni.princeton.edu]
> > >      Sent: Tuesday, June 18, 2002 22:24
> > >      To: xindice-users@xml.apache.org; prive@de-schepper.be
> > >      Subject: Re: nr of results && starting position
> > >      You would need to use the preceding-sibling construct of
> > >      XPath.  To get three items starting with the one with a
> > >      partiicular timestamp, you would return /mydoc/myitem
> > >      elements such that the timestamp of the context node, or its
> > >      preceding sibling, or the preceding sibling of its preceding
> > >      sibling was as specified. Jeff
> > >
> > >           From:develop@de-schepper.be
> > >           To: Xindice-Users
> > >           Sent: Tuesday, June 18, 2002 5:35 AM
> > >           Subject: nr of results && starting position
> > >           ...Now, I want to query this document for the next
> > >           2 items, starting with item which
> > >           timestamp='20020514124420645'the query I am
> > >           thinking of is something like this:xindice xpath
> > >           -c /db/mytestcol -q
> > >           "/mydoc/myitem[@timestamp='20020514124420645']"but
> > >           this will return only that one elementGuy
> > >

Re: nr of results && starting position

Posted by KOZLOV Roman <r-...@opencascade.com>.
Sorry, I've forgot the initial question conditions (identify item by some
attribute):

<xsl:template match="/">
    <xsl:apply-templates select="item[@name='theFirst']" mode="base">
        <xsl:with-param name="pos" select="39"/>
    </xsl:applyl-templates>
</xsl:template>

<xsl:template match="item" mode="base">
    <xsl:param name="pos"/>
    <xsl:variable name="lastpos" select="number($pos) + 100"/>
    <xsl:apply-templates select="item[((position() &lt; $lastpos) and
(position() &gt; $pos)) or (position() = $pos) ]" mode="iteration"/>
</xsl:template>

<xsl:template match="item" mode="iteration">
    . . .
</xsl:template>



KOZLOV Roman wrote:

> Try the following construction:
>
> <xsl:template match="/">
>     <xsl:call-template name="base">
>         <xsl:with-param name="pos" select="39"/>
>     </xsl:call-template>
> </xsl:template>
>
> <xsl:template name="base">
>     <xsl:param name="pos"/>
>     <xsl:variable name="lastpos" select="number($pos) + 100"/>
>     <xsl:apply-templates select="item[((position() &lt; $lastpos) and
> (position() &gt; $pos)) or (position() = $pos) ]" mode="iteration"/>
> </xsl:template>
>
> <xsl:template match="item" mode="iteration">
>     . . .
> </xsl:template>
>
> Best regards,
> Roman
>
> Guy De Schepper wrote:
>
> > ok, this query will indeed do the job for this example, but what about
> > large documents / collections ?let's say the document contains 10000
> > items and I want to display them with 100 at a time.for each page
> > (which will contain 100 items) I have to launch 100 queries !
> >
> >      -----Original Message-----
> >      From: Jeff Greif [mailto:jgreif@alumni.princeton.edu]
> >      Sent: Tuesday, June 18, 2002 22:24
> >      To: xindice-users@xml.apache.org; prive@de-schepper.be
> >      Subject: Re: nr of results && starting position
> >      You would need to use the preceding-sibling construct of
> >      XPath.  To get three items starting with the one with a
> >      partiicular timestamp, you would return /mydoc/myitem
> >      elements such that the timestamp of the context node, or its
> >      preceding sibling, or the preceding sibling of its preceding
> >      sibling was as specified. Jeff
> >
> >           From:develop@de-schepper.be
> >           To: Xindice-Users
> >           Sent: Tuesday, June 18, 2002 5:35 AM
> >           Subject: nr of results && starting position
> >           ...Now, I want to query this document for the next
> >           2 items, starting with item which
> >           timestamp='20020514124420645'the query I am
> >           thinking of is something like this:xindice xpath
> >           -c /db/mytestcol -q
> >           "/mydoc/myitem[@timestamp='20020514124420645']"but
> >           this will return only that one elementGuy
> >


Re: nr of results && starting position

Posted by KOZLOV Roman <r-...@opencascade.com>.
Try the following construction:

<xsl:template match="/">
    <xsl:call-template name="base">
        <xsl:with-param name="pos" select="39"/>
    </xsl:call-template>
</xsl:template>

<xsl:template name="base">
    <xsl:param name="pos"/>
    <xsl:variable name="lastpos" select="number($pos) + 100"/>
    <xsl:apply-templates select="item[((position() &lt; $lastpos) and
(position() &gt; $pos)) or (position() = $pos) ]" mode="iteration"/>
</xsl:template>

<xsl:template match="item" mode="iteration">
    . . .
</xsl:template>

Best regards,
Roman

Guy De Schepper wrote:

> ok, this query will indeed do the job for this example, but what about
> large documents / collections ?let's say the document contains 10000
> items and I want to display them with 100 at a time.for each page
> (which will contain 100 items) I have to launch 100 queries !
>
>      -----Original Message-----
>      From: Jeff Greif [mailto:jgreif@alumni.princeton.edu]
>      Sent: Tuesday, June 18, 2002 22:24
>      To: xindice-users@xml.apache.org; prive@de-schepper.be
>      Subject: Re: nr of results && starting position
>      You would need to use the preceding-sibling construct of
>      XPath.  To get three items starting with the one with a
>      partiicular timestamp, you would return /mydoc/myitem
>      elements such that the timestamp of the context node, or its
>      preceding sibling, or the preceding sibling of its preceding
>      sibling was as specified. Jeff
>
>           From:develop@de-schepper.be
>           To: Xindice-Users
>           Sent: Tuesday, June 18, 2002 5:35 AM
>           Subject: nr of results && starting position
>           ...Now, I want to query this document for the next
>           2 items, starting with item which
>           timestamp='20020514124420645'the query I am
>           thinking of is something like this:xindice xpath
>           -c /db/mytestcol -q
>           "/mydoc/myitem[@timestamp='20020514124420645']"but
>           this will return only that one elementGuy
>


Re: nr of results && starting position

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
MessageTo browse the items in the document in pages of 100 at a time, you
could use (for the second page) the XPath

/mydoc/myitem[position() >= 101 and position() < 200]

To answer questions like these, one need only refer to the XPath spec
http://www.w3.org/TR/xpath

Jeff
----- Original Message -----
From: Guy De Schepper
To: 'Jeff Greif' ; xindice-users@xml.apache.org
Sent: Tuesday, June 18, 2002 11:37 PM
Subject: RE: nr of results && starting position


ok, this query will indeed do the job for this example, but what about large
documents / collections ?

let's say the document contains 10000 items and I want to display them with
100 at a time.
for each page (which will contain 100 items) I have to launch 100 queries !



RE: nr of results && starting position

Posted by Guy De Schepper <pr...@de-schepper.be>.
ok, this query will indeed do the job for this example, but what about
large documents / collections ?
 
let's say the document contains 10000 items and I want to display them
with 100 at a time.
for each page (which will contain 100 items) I have to launch 100
queries !

-----Original Message-----
From: Jeff Greif [mailto:jgreif@alumni.princeton.edu] 
Sent: Tuesday, June 18, 2002 22:24
To: xindice-users@xml.apache.org; prive@de-schepper.be
Subject: Re: nr of results && starting position


You would need to use the preceding-sibling construct of XPath.  To get
three items starting with the one with a partiicular timestamp, you
would return /mydoc/myitem elements such that the timestamp of the
context node, or its preceding sibling, or the preceding sibling of its
preceding sibling was as specified.
 
Jeff

From: develop@de-schepper.be 
To: Xindice-Users <ma...@xml.apache.org>  
Sent: Tuesday, June 18, 2002 5:35 AM
Subject: nr of results && starting position

...
 
Now, I want to query this document for the next 2 items, starting with
item which timestamp='20020514124420645'
 
the query I am thinking of is something like this:
xindice xpath -c /db/mytestcol -q
"/mydoc/myitem[@timestamp='20020514124420645']"
 
but this will return only that one element
 
 
 
Guy


Re: nr of results && starting position

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
MessageYou would need to use the preceding-sibling construct of XPath.  To get three items starting with the one with a partiicular timestamp, you would return /mydoc/myitem elements such that the timestamp of the context node, or its preceding sibling, or the preceding sibling of its preceding sibling was as specified.

Jeff
  From: develop@de-schepper.be 
  To: Xindice-Users 
  Sent: Tuesday, June 18, 2002 5:35 AM
  Subject: nr of results && starting position


  ...

  Now, I want to query this document for the next 2 items, starting with item which timestamp='20020514124420645'

  the query I am thinking of is something like this:
  xindice xpath -c /db/mytestcol -q "/mydoc/myitem[@timestamp='20020514124420645']"

  but this will return only that one element



  Guy