A discussion on the saxon list recently reminded me that key() doesn't work unless the XML tree has a document root - this is per-spec (although Michael Kay argued that the spec authors may not have made the best decision on that aspect).
http://www.w3.org/TR/xslt20/#function-key [ERR XTDE1270] It is a non-recoverable dynamic error<http://www.w3.org/TR/xslt20/#dt-nonrec-dynamic-error> to call the key<http://www.w3.org/TR/xslt20/#function-key> function with two arguments if there is no context node<http://www.w3.org/TR/xslt20/#dt-context-node>, or if the root of the tree containing the context node is not a document node; or to call the function with three arguments if the root of the tree containing the node supplied in the third argument is not a document node. From: [email protected] [mailto:[email protected]] On Behalf Of Christopher Hamlin Sent: Friday, March 28, 2014 10:16 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] Stylesheet issue Hi Vijay, I think it has to do with passing an element instead of a document to the xslt. Check out the usage notest for xslt-eval. While playing around I also got the impression that key() may need to be used in a document-rooted node. Anyway, try wrapping your data up as document { <persons> ... </persons> } That worked for me. - Chris On Fri, Mar 28, 2014 at 4:39 AM, Vijayasekar Padmanaban <[email protected]<mailto:[email protected]>> wrote: Hi, I am trying to transform xml using stylesheet in Marklogic 6.0-4 version. I see a strange problem with keys used in stylesheet. The below code gives me empty result whereas I expect it to return some results. Can someone tell me what could be the problem is? xdmp:xslt-eval( <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:key name="preg" match="person" use="@id"/> <xsl:template match="/"> <html> <body> <xsl:for-each select="key('preg','050676')"> <p> Id: <xsl:value-of select="@id"/><br /> Name: <xsl:value-of select="@name"/> </p> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> , <persons> <person name="Tarzan" id="050676"/> <person name="Donald" id="070754"/> <person name="Dolly" id="050686"/> </persons>,()) Regards Vijay
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
