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: [email protected]
[[email protected]] on behalf of Erik Zander
[[email protected]]
Sent: Thursday, July 31, 2014 1: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:[email protected]]
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 <[email protected]> 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) <xsl:result-document href="out/{
> $id }.xml" method="xml" indent="yes"> </xsl:result-document> -- 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:[email protected]]
> 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:
>
> <xsl:template match="//db:informalfigure[descendant::db:imagedata and
> @role='figure']">
>
>
>
> <xsl:variable name="curImage"
> select="substring-after(.//@fileref,'/')"/>
>
> <xsl:variable name="id"
> select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/>
> <xsl:if
> test="not(doc-available(xdmp:resolve-uri(string-join(('out/',$id,'.xml'),''),xdmp:node-uri(.))))">
> <!--This check fails, am I doing it incorrectly or is it the way xslt
> processes document that makes it hard to check if the id have been
> encountered before?-->
>
> <xsl:result-document method="xml" href="out/{$id}.xml"
> indent="yes">
>
>
> On Mon, Jul 28, 2014 at 9:08 AM, Mary Holstege <[email protected]>
> 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
> <[email protected]> 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
> > <xsl:template match="//db:informalfigure[descendant::db:imagedata
> > and @role='figure']">
> >
> >
> >
> > <xsl:variable name="curImage"
> > select="substring-after(.//@fileref,'/')"/>
> >
> > <xsl:variable name="id"
> > select="$imageMetaData//image[name=string-join(($curISBN,$curImage),'/')]/id"/>
> > <xsl:if
> > test="not(doc-available(string-join(('out/',$id,'.xml'),'')))">
> > <!--This check fails, am I doing it incorrectly or is it the way
> > xslt processes document that makes it hard to check if the id have
> > been encountered before?-->
> >
> > <xsl:result-document method="xml" href="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
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general