[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: are there non streaming use cases of fn:snapshot

Subject: Re: are there non streaming use cases of fn:snapshot function
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Mar 2019 08:42:42 -0000
Re:  are there non streaming use cases of fn:snapshot
I can't think of any persuasive use cases. If your original data fits in
memory, then there is little reason to make a snapshot copy of it, you might
as well use the original. The point about snapshot is that it is designed to
capture the content of a node and its immediate "relatives" (the ones you are
most likely to need access to) without the memory overhead of holding the
whole document; so it's all about memory use.

I guess there could be cases where the output of snapshot() happens to be
exactly the data that you want to put into a serialized message and send to
some other system, but it's more likely in general that you would want to
control the message content more precisely than this.

Michael Kay
Saxonica

> On 15 Mar 2019, at 06:07, Mukul Gandhi gandhi.mukul@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi all,
>    I've read the XSLT 3.0 spec for fn:snapshot function. As stated in the
spec, this function has lots of uses while using streaming, which is great.
>
> I've come up with following XSLT 3.0 example (that runs fine even with Saxon
HE 9.8) using fn:snapshot function, when not using streaming features of XSLT
language,
>
> XML input:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>    <x id="a">
>      <y>5</y>
>    </x>
>    <x id="b">
>      <y>4</y>
>    </x>
>    <x id="c">
>      <y>3</y>
>    </x>
>    <x id="d">
>      <y>2</y>
>    </x>
>    <x id="e">
>      <y>1</y>
>    </x>
> </root>
>
> XSLT stylesheet:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform>"
>                          version="3.0">
>
>     <xsl:output method="xml" indent="yes"/>
>
>     <xsl:template match="root">
>        <xsl:variable name="yTemp" select="x[2]/y"/>
>         <result>
>            <xsl:variable name="yVar1" as="element(y)">
>               <xsl:copy-of select="$yTemp"/>
>            </xsl:variable>
>            <parent parentsName="{local-name($yVar1/..)}"
parentsParentName="{local-name($yVar1/../..)}">
>               <xsl:copy-of select="$yVar1"/>
>            </parent>
>            <xsl:variable name="yVar2" select="snapshot($yTemp)"
as="element(y)"/>
>            <parent parentsName="{local-name($yVar2/..)}"
parentsParentName="{local-name($yVar2/../..)}">
>               <one>
>                  <xsl:copy-of select="$yVar2"/>
>               </one>
>               <two>
>                  <xsl:copy-of select="$yVar2/../.."/>
>               </two>
>            </parent>
>         </result>
>     </xsl:template>
>
> </xsl:stylesheet>
>
> The output of above XSLT transformation is:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <result>
>    <parent parentsName="" parentsParentName="">
>        <y>4</y>
>    </parent>
>    <parent parentsName="x" parentsParentName="root">
>       <one>
>          <y>4</y>
>       </one>
>       <two>
>          <root>
>             <x id="b">
>                <y>4</y>
>             </x>
>          </root>
>       </two>
>    </parent>
> </result>
>
> In this example, I was also trying to understand the difference between
output of xsl:copy-of and fn:snapshot. The spec of fn:snapshot says, "Returns
a copy of a sequence, retaining copies of the ancestors and descendants of any
node in the input sequence, together with their attributes and namespaces".
>
> Particularly, the ability of fn:snapshot function to retain ancestors and
descendants of nodes (which xsl:copy-of can't do) in the input sequence amazed
me. The contents of element "two" in above XML output, reflects this. I
particularly like, the projection of "root" element ('root' and output below
it) in above example.
>
> I'm curious to know, what could be good non streaming use cases of
fn:snapshot function ?
>
>
>
>
> --
> Regards,
> Mukul Gandhi
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread

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-2013 All Rights Reserved.