Subject: Re: [xsl] how to keep context when copying From: Andrew Welch <andrew.j.welch@xxxxxxxxx> Date: Tue, 18 Aug 2009 15:03:51 +0100 |
2009/8/18 Andy Chambers <achambers.home@xxxxxxxxxxxxxx>: > Hey All, > > Is there a way of keeping the context information when you copy a > node? Here's my use-case.... > > I have a document that has "refs" and "defs" and I'd like to write a > function that returns a "def" > node when you pass it a "ref". > > I've got this working fine using keys to lookup the defs. The > fdx:GetDef function basically boils > down to the following template (XSLT 2)....(it's actually a little > more complicated because depending > on the type of the "ref", it has to go lookup a different key) > > <xsl:function name="fdx:GetDef"> > <xsl:param name="ref"/> > <xsl:copy-of select="key('keyItems', $ref/@OID)"/> > </xsl:function> > > My problem is that the nodes returned by this function lack ancestor > info that would be useful > in downstream processing of the node. Is there a way that I can > rewrite the function to return > a node that allows me to get at the node's ancestors for example. Use xsl:sequence instead of xsl:copy-of, as that returns pointers to the nodes in their original location rather copies. However, you would also need to pass in the context wouldn't you? It's also good practice to state the param and return types (use the "as" attribute on the params and function definition) -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] how to keep context when , Michael Kay | Thread | [xsl] Convert SGML to XML using Jam, sa ku |
RE: [xsl] how to keep context when , Michael Kay | Date | Re: [xsl] how to keep context when , Andy Chambers |
Month |