Re: [MarkLogic Dev General] XSLT check if result document has been created
Hi Just a last update on this, First of all thanks for all suggestions, after suggestions from a friend I ended up with was using recursion. Thanks again Erik -Ursprungligt meddelande- Från: Garrow, Heather [mailto:hgar...@newsbank.com] Skickat: den 31 juli 2014 13:45 Till: MarkLogic Developer Discussion Ämne: Re: [MarkLogic Dev General] XSLT check if result document has been created The closest thing to a map I've found in XSLT is -Original Message- From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Erik Zander Sent: Thursday, July 31, 2014 4:16 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XSLT check if result document has been created Hello Mike Yes to use a map would be ideal, and actually one of my first thoughts however upon googling for maps and xslt I got the impression that XSLT doesn't have maps, is that the case? If so I would have to write my own map which I admit I haven't yet figured out as XSLT is declarative... Once or twice I miss java... Anyway thanks for pointing out a direction :) Regards Erik -Ursprungligt meddelande- Från: Michael Blakeley [mailto:m...@blakeley.com] Skickat: den 29 juli 2014 20:17 Till: MarkLogic Developer Discussion Ämne: Re: [MarkLogic Dev General] XSLT check if result document has been created If you want to skip the duplicates, one common pattern is to track them using a map. You could also use distinct-values, but a map can be more efficient. let $m-seen := map:map() for $i in $list let $key := $i/@id/string() (: Or some other expr based on $i :) let $is-duplicate := map:contains($m-seen, $key) let $_ := if ($is-duplicate) then () else map:put($m-seen, $key, 1) where not($is-duplicate) return $i (: Or do other processing on $i :) The map starts empty. While processing each item we check to see if it already has a map entry. If it does, we consider it a duplicate and do nothing. Otherwise we add it to the map and finish processing it. So if there are two or more items with the same @id value, only the first one will be processed. Translating this logic into XSLT is left as an exercise. The logic is the same but you'd use xsl:variable elements, etc. -- Mike On 29 Jul 2014, at 03:31 , Erik Zander wrote: > Thank you Ryan and Mary > > Sadly it didn't work as I wished for, I still get duplicate uris which is > what the if statement was introduced to remove.. > XSLT-DUPRESULTURIS: (err:XTDE1490) -- Two > final trees cannot have the same URI: > out/36CD63C6006FE011A8EE9FEB54B1132A.xml > > I have not yet understood completely in what ways it's possible to read and > manipulate the result tree in xslt, if I only could address that I would be > able to see if a specific id was in the result tree and then not process. > But as it stands now I think I have to rethink how I can make sure to only > process each image once even thou its reoccurring in the source xml. > Thanks anyway > /Erik Zander > Från: Ryan Dew [mailto:ryan.j@gmail.com] > Skickat: den 28 juli 2014 17:20 > Till: MarkLogic Developer Discussion > Ämne: Re: [MarkLogic Dev General] XSLT check if result document has > been created > > I believe you should be able to do something like the following to get what > you want: > > > > > > select="substring-after(.//@fileref,'/')"/> > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > test="not(doc-available(xdmp:resolve-uri(string-join(('out/',$id,'.xml'),''),xdmp:node-uri(."> > > > indent="yes"> > > > On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege > wrote: > > I think you may be running afoul of URI resolution. > Since the URI you are giving to doc-available is a relative URI, it > will be resolved relative to the static base URI, which per XSLT is > the URI of the stylesheet itself. > > //Mary > > On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander > wrote: > > > Hi All > > > > I'm working on an xslt transform where I'm extracting data about > > images from a document and put that data into result document, It > > all works fine except for when the same image occurs more than once > > as I then get conflicting uris, > > > > my code looks like this > > > > > > > > > > > select="substring-after(.//@fileref,'/')"/> > > > > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > > &
Re: [MarkLogic Dev General] XSLT check if result document has been created
Hi, Erik: In MarkLogic, you can use a map in XSLT. You need to declare the map namespace. Here is an example from the use of transforms in the REST API: http://docs.marklogic.com/guide/rest-dev/transforms#id_16898 In nominal solidarity, Erik Hennum From: general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.com] on behalf of Erik Zander [erik.zan...@studentlitteratur.se] Sent: Thursday, July 31, 2014 1:16 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XSLT check if result document has beencreated Hello Mike Yes to use a map would be ideal, and actually one of my first thoughts however upon googling for maps and xslt I got the impression that XSLT doesn't have maps, is that the case? If so I would have to write my own map which I admit I haven't yet figured out as XSLT is declarative... Once or twice I miss java... Anyway thanks for pointing out a direction :) Regards Erik -Ursprungligt meddelande- Från: Michael Blakeley [mailto:m...@blakeley.com] Skickat: den 29 juli 2014 20:17 Till: MarkLogic Developer Discussion Ämne: Re: [MarkLogic Dev General] XSLT check if result document has been created If you want to skip the duplicates, one common pattern is to track them using a map. You could also use distinct-values, but a map can be more efficient. let $m-seen := map:map() for $i in $list let $key := $i/@id/string() (: Or some other expr based on $i :) let $is-duplicate := map:contains($m-seen, $key) let $_ := if ($is-duplicate) then () else map:put($m-seen, $key, 1) where not($is-duplicate) return $i (: Or do other processing on $i :) The map starts empty. While processing each item we check to see if it already has a map entry. If it does, we consider it a duplicate and do nothing. Otherwise we add it to the map and finish processing it. So if there are two or more items with the same @id value, only the first one will be processed. Translating this logic into XSLT is left as an exercise. The logic is the same but you'd use xsl:variable elements, etc. -- Mike On 29 Jul 2014, at 03:31 , Erik Zander wrote: > Thank you Ryan and Mary > > Sadly it didn't work as I wished for, I still get duplicate uris which is > what the if statement was introduced to remove.. > XSLT-DUPRESULTURIS: (err:XTDE1490) -- Two > final trees cannot have the same URI: > out/36CD63C6006FE011A8EE9FEB54B1132A.xml > > I have not yet understood completely in what ways it's possible to read and > manipulate the result tree in xslt, if I only could address that I would be > able to see if a specific id was in the result tree and then not process. > But as it stands now I think I have to rethink how I can make sure to only > process each image once even thou its reoccurring in the source xml. > Thanks anyway > /Erik Zander > Från: Ryan Dew [mailto:ryan.j@gmail.com] > Skickat: den 28 juli 2014 17:20 > Till: MarkLogic Developer Discussion > Ämne: Re: [MarkLogic Dev General] XSLT check if result document has > been created > > I believe you should be able to do something like the following to get what > you want: > > > > > > select="substring-after(.//@fileref,'/')"/> > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > test="not(doc-available(xdmp:resolve-uri(string-join(('out/',$id,'.xml'),''),xdmp:node-uri(."> > > > indent="yes"> > > > On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege > wrote: > > I think you may be running afoul of URI resolution. > Since the URI you are giving to doc-available is a relative URI, it > will be resolved relative to the static base URI, which per XSLT is > the URI of the stylesheet itself. > > //Mary > > On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander > wrote: > > > Hi All > > > > I'm working on an xslt transform where I'm extracting data about > > images from a document and put that data into result document, It > > all works fine except for when the same image occurs more than once > > as I then get conflicting uris, > > > > my code looks like this > > > > > > > > > > > select="substring-after(.//@fileref,'/')"/> > > > > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > > > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))"> > > > > > > > indent="yes&quo
Re: [MarkLogic Dev General] XSLT check if result document has been created
The closest thing to a map I've found in XSLT is -Original Message- From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Erik Zander Sent: Thursday, July 31, 2014 4:16 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] XSLT check if result document has been created Hello Mike Yes to use a map would be ideal, and actually one of my first thoughts however upon googling for maps and xslt I got the impression that XSLT doesn't have maps, is that the case? If so I would have to write my own map which I admit I haven't yet figured out as XSLT is declarative... Once or twice I miss java... Anyway thanks for pointing out a direction :) Regards Erik -Ursprungligt meddelande- Från: Michael Blakeley [mailto:m...@blakeley.com] Skickat: den 29 juli 2014 20:17 Till: MarkLogic Developer Discussion Ämne: Re: [MarkLogic Dev General] XSLT check if result document has been created If you want to skip the duplicates, one common pattern is to track them using a map. You could also use distinct-values, but a map can be more efficient. let $m-seen := map:map() for $i in $list let $key := $i/@id/string() (: Or some other expr based on $i :) let $is-duplicate := map:contains($m-seen, $key) let $_ := if ($is-duplicate) then () else map:put($m-seen, $key, 1) where not($is-duplicate) return $i (: Or do other processing on $i :) The map starts empty. While processing each item we check to see if it already has a map entry. If it does, we consider it a duplicate and do nothing. Otherwise we add it to the map and finish processing it. So if there are two or more items with the same @id value, only the first one will be processed. Translating this logic into XSLT is left as an exercise. The logic is the same but you'd use xsl:variable elements, etc. -- Mike On 29 Jul 2014, at 03:31 , Erik Zander wrote: > Thank you Ryan and Mary > > Sadly it didn't work as I wished for, I still get duplicate uris which is > what the if statement was introduced to remove.. > XSLT-DUPRESULTURIS: (err:XTDE1490) -- Two > final trees cannot have the same URI: > out/36CD63C6006FE011A8EE9FEB54B1132A.xml > > I have not yet understood completely in what ways it's possible to read and > manipulate the result tree in xslt, if I only could address that I would be > able to see if a specific id was in the result tree and then not process. > But as it stands now I think I have to rethink how I can make sure to only > process each image once even thou its reoccurring in the source xml. > Thanks anyway > /Erik Zander > Från: Ryan Dew [mailto:ryan.j@gmail.com] > Skickat: den 28 juli 2014 17:20 > Till: MarkLogic Developer Discussion > Ämne: Re: [MarkLogic Dev General] XSLT check if result document has > been created > > I believe you should be able to do something like the following to get what > you want: > > > > > > select="substring-after(.//@fileref,'/')"/> > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > test="not(doc-available(xdmp:resolve-uri(string-join(('out/',$id,'.xml'),''),xdmp:node-uri(."> > > > indent="yes"> > > > On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege > wrote: > > I think you may be running afoul of URI resolution. > Since the URI you are giving to doc-available is a relative URI, it > will be resolved relative to the static base URI, which per XSLT is > the URI of the stylesheet itself. > > //Mary > > On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander > wrote: > > > Hi All > > > > I'm working on an xslt transform where I'm extracting data about > > images from a document and put that data into result document, It > > all works fine except for when the same image occurs more than once > > as I then get conflicting uris, > > > > my code looks like this > > > > > > > > > > > select="substring-after(.//@fileref,'/')"/> > > > > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > > > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))"> > > > > > > > indent="yes"> > > > > Ideally I would like to be able to check if the result document have > > been created or not and after that decide if I want to update it >
Re: [MarkLogic Dev General] XSLT check if result document has been created
Hello Mike Yes to use a map would be ideal, and actually one of my first thoughts however upon googling for maps and xslt I got the impression that XSLT doesn't have maps, is that the case? If so I would have to write my own map which I admit I haven't yet figured out as XSLT is declarative... Once or twice I miss java... Anyway thanks for pointing out a direction :) Regards Erik -Ursprungligt meddelande- Från: Michael Blakeley [mailto:m...@blakeley.com] Skickat: den 29 juli 2014 20:17 Till: MarkLogic Developer Discussion Ämne: Re: [MarkLogic Dev General] XSLT check if result document has been created If you want to skip the duplicates, one common pattern is to track them using a map. You could also use distinct-values, but a map can be more efficient. let $m-seen := map:map() for $i in $list let $key := $i/@id/string() (: Or some other expr based on $i :) let $is-duplicate := map:contains($m-seen, $key) let $_ := if ($is-duplicate) then () else map:put($m-seen, $key, 1) where not($is-duplicate) return $i (: Or do other processing on $i :) The map starts empty. While processing each item we check to see if it already has a map entry. If it does, we consider it a duplicate and do nothing. Otherwise we add it to the map and finish processing it. So if there are two or more items with the same @id value, only the first one will be processed. Translating this logic into XSLT is left as an exercise. The logic is the same but you'd use xsl:variable elements, etc. -- Mike On 29 Jul 2014, at 03:31 , Erik Zander wrote: > Thank you Ryan and Mary > > Sadly it didn't work as I wished for, I still get duplicate uris which is > what the if statement was introduced to remove.. > XSLT-DUPRESULTURIS: (err:XTDE1490) -- Two > final trees cannot have the same URI: > out/36CD63C6006FE011A8EE9FEB54B1132A.xml > > I have not yet understood completely in what ways it's possible to read and > manipulate the result tree in xslt, if I only could address that I would be > able to see if a specific id was in the result tree and then not process. > But as it stands now I think I have to rethink how I can make sure to only > process each image once even thou its reoccurring in the source xml. > Thanks anyway > /Erik Zander > Från: Ryan Dew [mailto:ryan.j@gmail.com] > Skickat: den 28 juli 2014 17:20 > Till: MarkLogic Developer Discussion > Ämne: Re: [MarkLogic Dev General] XSLT check if result document has > been created > > I believe you should be able to do something like the following to get what > you want: > > > > > > select="substring-after(.//@fileref,'/')"/> > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > test="not(doc-available(xdmp:resolve-uri(string-join(('out/',$id,'.xml'),''),xdmp:node-uri(."> > > > indent="yes"> > > > On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege > wrote: > > I think you may be running afoul of URI resolution. > Since the URI you are giving to doc-available is a relative URI, it > will be resolved relative to the static base URI, which per XSLT is > the URI of the stylesheet itself. > > //Mary > > On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander > wrote: > > > Hi All > > > > I'm working on an xslt transform where I'm extracting data about > > images from a document and put that data into result document, It > > all works fine except for when the same image occurs more than once > > as I then get conflicting uris, > > > > my code looks like this > > > > > > > > > > > select="substring-after(.//@fileref,'/')"/> > > > > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > > > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))"> > > > > > > > indent="yes"> > > > > Ideally I would like to be able to check if the result document have > > been created or not and after that decide if I want to update it > > with more information or just leave it be. > > > > Would appreciate any help on the subject > > > > Best regards > > Erik > > > -- > Using Opera's revolutionary email client: http://www.opera.com/mail/ > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] XSLT check if result document has been created
If you want to skip the duplicates, one common pattern is to track them using a map. You could also use distinct-values, but a map can be more efficient. let $m-seen := map:map() for $i in $list let $key := $i/@id/string() (: Or some other expr based on $i :) let $is-duplicate := map:contains($m-seen, $key) let $_ := if ($is-duplicate) then () else map:put($m-seen, $key, 1) where not($is-duplicate) return $i (: Or do other processing on $i :) The map starts empty. While processing each item we check to see if it already has a map entry. If it does, we consider it a duplicate and do nothing. Otherwise we add it to the map and finish processing it. So if there are two or more items with the same @id value, only the first one will be processed. Translating this logic into XSLT is left as an exercise. The logic is the same but you'd use xsl:variable elements, etc. -- Mike On 29 Jul 2014, at 03:31 , Erik Zander wrote: > Thank you Ryan and Mary > > Sadly it didn’t work as I wished for, I still get duplicate uris which is > what the if statement was introduced to remove…. > XSLT-DUPRESULTURIS: (err:XTDE1490) mailto:ryan.j@gmail.com] > Skickat: den 28 juli 2014 17:20 > Till: MarkLogic Developer Discussion > Ämne: Re: [MarkLogic Dev General] XSLT check if result document has been > created > > I believe you should be able to do something like the following to get what > you want: > > > > > > select="substring-after(.//@fileref,'/')"/> > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > test="not(doc-available(xdmp:resolve-uri(string-join(('out/',$id,'.xml'),''),xdmp:node-uri(."> > > > indent="yes"> > > > On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege > wrote: > > I think you may be running afoul of URI resolution. > Since the URI you are giving to doc-available is a relative > URI, it will be resolved relative to the static base URI, which > per XSLT is the URI of the stylesheet itself. > > //Mary > > On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander > wrote: > > > Hi All > > > > I’m working on an xslt transform where I’m extracting data about images > > from a document and put > > that data into result document, It all works fine except for when the > > same image occurs more than once as I then get conflicting uris, > > > > my code looks like this > > > > > > > > > > > select="substring-after(.//@fileref,'/')"/> > > > > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > > > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))"> > > > > > > > indent="yes"> > > > > Ideally I would like to be able to check if the result document have > > been created or not and after that decide if I want to update it with > > more information or just leave it be. > > > > Would appreciate any help on the subject > > > > Best regards > > Erik > > > -- > Using Opera's revolutionary email client: http://www.opera.com/mail/ > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] XSLT check if result document has been created
Thank you Ryan and Mary Sadly it didn’t work as I wished for, I still get duplicate uris which is what the if statement was introduced to remove…. XSLT-DUPRESULTURIS: (err:XTDE1490) mailto:ryan.j@gmail.com] Skickat: den 28 juli 2014 17:20 Till: MarkLogic Developer Discussion Ämne: Re: [MarkLogic Dev General] XSLT check if result document has been created I believe you should be able to do something like the following to get what you want: mailto:.//@fileref,'/')%22/>> On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege mailto:mary.holst...@marklogic.com>> wrote: I think you may be running afoul of URI resolution. Since the URI you are giving to doc-available is a relative URI, it will be resolved relative to the static base URI, which per XSLT is the URI of the stylesheet itself. //Mary On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander mailto:erik.zan...@studentlitteratur.se>> wrote: > Hi All > > I’m working on an xslt transform where I’m extracting data about images > from a document and put > that data into result document, It all works fine except for when the > same image occurs more than once as I then get conflicting uris, > > my code looks like this > > > > > select="substring-after(.//@fileref,'/')"/<mailto:.//@fileref,'/')%22/>> > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))"> > > > indent="yes"> > > Ideally I would like to be able to check if the result document have > been created or not and after that decide if I want to update it with > more information or just leave it be. > > Would appreciate any help on the subject > > Best regards > Erik -- Using Opera's revolutionary email client: http://www.opera.com/mail/ ___ General mailing list General@developer.marklogic.com<mailto:General@developer.marklogic.com> http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] XSLT check if result document has been created
I believe you should be able to do something like the following to get what you want: On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege wrote: > > I think you may be running afoul of URI resolution. > Since the URI you are giving to doc-available is a relative > URI, it will be resolved relative to the static base URI, which > per XSLT is the URI of the stylesheet itself. > > //Mary > > On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander > wrote: > > > Hi All > > > > I’m working on an xslt transform where I’m extracting data about images > > from a document and put > > that data into result document, It all works fine except for when the > > same image occurs more than once as I then get conflicting uris, > > > > my code looks like this > > > > > > > > > > > select="substring-after(.//@fileref,'/')"/> > > > > > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > > > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))"> > > > > > > > indent="yes"> > > > > Ideally I would like to be able to check if the result document have > > been created or not and after that decide if I want to update it with > > more information or just leave it be. > > > > Would appreciate any help on the subject > > > > Best regards > > Erik > > > -- > Using Opera's revolutionary email client: http://www.opera.com/mail/ > ___ > General mailing list > General@developer.marklogic.com > http://developer.marklogic.com/mailman/listinfo/general > ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] XSLT check if result document has been created
I think you may be running afoul of URI resolution. Since the URI you are giving to doc-available is a relative URI, it will be resolved relative to the static base URI, which per XSLT is the URI of the stylesheet itself. //Mary On Mon, 28 Jul 2014 07:58:04 -0700, Erik Zander wrote: > Hi All > > I’m working on an xslt transform where I’m extracting data about images > from a document and put > that data into result document, It all works fine except for when the > same image occurs more than once as I then get conflicting uris, > > my code looks like this > > > > > select="substring-after(.//@fileref,'/')"/> > > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/> > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))"> > > > indent="yes"> > > Ideally I would like to be able to check if the result document have > been created or not and after that decide if I want to update it with > more information or just leave it be. > > Would appreciate any help on the subject > > Best regards > Erik -- Using Opera's revolutionary email client: http://www.opera.com/mail/ ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
[MarkLogic Dev General] XSLT check if result document has been created
Hi All I’m working on an xslt transform where I’m extracting data about images from a document and put that data into result document, It all works fine except for when the same image occurs more than once as I then get conflicting uris, my code looks like this Ideally I would like to be able to check if the result document have been created or not and after that decide if I want to update it with more information or just leave it be. Would appreciate any help on the subject Best regards Erik ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general