xsl-list
[Top] [All Lists]

Re: [xsl] how to keep context when copying

2009-08-18 10:04:16
2009/8/18 Andy Chambers <achambers(_dot_)home(_at_)googlemail(_dot_)com>:
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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>