xsl:number with stream ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

xsl:number with stream ?

Vincent Cestmois
Hi,

I've this code, which works perfectly if I don't use the stream functionality.
But I need streaming because the file is huge.

It throws this error

* Operand . of xsl:number selects streamed nodes in a context that allows arbitrary navigation

Is there any way to make it work.
I use saxon 9.7.0.8 EE

<xsl:for-each select="EAN_UPCS/EAN_UPC">
<ROW MODID="" RECORDID="">
<COL><DATA><xsl:value-of select="../../@Product_ID"/></DATA></COL>
<COL><DATA><xsl:value-of select="@Value"/></DATA></COL>
<COL><DATA><xsl:number/></DATA></COL>
</ROW>
</xsl:for-each>


Basically a Product can have several EAN (barcodes), and I just want the order of each one for that product.

So the output would be

1485 (the product ID)  4128796521452 (the ean) 1 (the order)
1485 (the product ID)  8956796521452 (the ean) 2 (the order)
1486 (the product ID)  3218796521452 (the ean) 1 (the order)
1486 (the product ID)  7536796521452 (the ean) 2 (the order)


So is there a streamable alternative, or something to improve my xsl:number syntax.

Thanks.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: xsl:number with stream ?

Michael Kay
It seems to me that in this very simple case xsl:number is doing almost exactly the same as <xsl:value-of select="position()"/>, which is streamable. Except that you may need to nest the for-each

<for-each select="EAN_UPCS">
   <xsl:for-each select="EAN_UPC">

if you want numbering to restart at 1 for each iteration of the inner loop.

For a slightly more complex case you could use xsl:iterate:

<xsl:iterate select="EAN_UPCS/EAN_UPC" expand-text="yes">
  <xsl:param name="n" as="xs:integer" select="1"/>
  <ROW MODID="" RECORDID="">
  <COL><DATA>{../../@Product_ID}</DATA></COL>
  <COL><DATA>{@Value}</DATA></COL>
  <COL><DATA>{$n}></DATA></COL>
  </ROW>
  <xsl:next-iteration>
    <xsl:with-param name="n" select="if (....) then 1 else $n+1"/>
  </xsl:next-iteration>
</xsl:iterate>

For more complex use cases still of xsl:number, you need to look at accumulators.

Michael Kay
Saxonica


> On 6 Oct 2016, at 08:27, Vincent Cestmois <[hidden email]> wrote:
>
> Hi,
>
> I've this code, which works perfectly if I don't use the stream functionality.
> But I need streaming because the file is huge.
>
> It throws this error
>
> * Operand . of xsl:number selects streamed nodes in a context that allows arbitrary navigation
>
> Is there any way to make it work.
> I use saxon 9.7.0.8 EE
>
> <xsl:for-each select="EAN_UPCS/EAN_UPC">
> <ROW MODID="" RECORDID="">
> <COL><DATA><xsl:value-of select="../../@Product_ID"/></DATA></COL>
> <COL><DATA><xsl:value-of select="@Value"/></DATA></COL>
> <COL><DATA><xsl:number/></DATA></COL>
> </ROW>
> </xsl:for-each>
>
>
> Basically a Product can have several EAN (barcodes), and I just want the order of each one for that product.
>
> So the output would be
>
> 1485 (the product ID)  4128796521452 (the ean) 1 (the order)
> 1485 (the product ID)  8956796521452 (the ean) 2 (the order)
> 1486 (the product ID)  3218796521452 (the ean) 1 (the order)
> 1486 (the product ID)  7536796521452 (the ean) 2 (the order)
>
>
> So is there a streamable alternative, or something to improve my xsl:number syntax.
>
> Thanks.
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot_______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: xsl:number with stream ?

Vincent Cestmois
In reply to this post by Vincent Cestmois
Amazing Michael, position() worked great
Many thanks for your awesome support !

2016-10-06 9:27 GMT+02:00 Vincent Cestmois <[hidden email]>:
Hi,

I've this code, which works perfectly if I don't use the stream functionality.
But I need streaming because the file is huge.

It throws this error

* Operand . of xsl:number selects streamed nodes in a context that allows arbitrary navigation

Is there any way to make it work.
I use saxon 9.7.0.8 EE

<xsl:for-each select="EAN_UPCS/EAN_UPC">
<ROW MODID="" RECORDID="">
<COL><DATA><xsl:value-of select="../../@Product_ID"/></DATA></COL>
<COL><DATA><xsl:value-of select="@Value"/></DATA></COL>
<COL><DATA><xsl:number/></DATA></COL>
</ROW>
</xsl:for-each>


Basically a Product can have several EAN (barcodes), and I just want the order of each one for that product.

So the output would be

1485 (the product ID)  4128796521452 (the ean) 1 (the order)
1485 (the product ID)  8956796521452 (the ean) 2 (the order)
1486 (the product ID)  3218796521452 (the ean) 1 (the order)
1486 (the product ID)  7536796521452 (the ean) 2 (the order)


So is there a streamable alternative, or something to improve my xsl:number syntax.

Thanks.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help