Fred Finkle
Fred Finkle

Reputation: 2017

XSLT - How can I save a node from one document in another temp document and later retrieve it?

This isn't exactly what I want to do, but it's a simple case of the functionality I need. I want to alternate between processing nodes in one document and processing nodes in a temp document that was created during the processing of the original document. To do this, I want to "save" a node from the original document into the temp document so I can go back to it. I can easily "save" the node itself into the temp document, but being part of the temp document I can no longer do things like test if another node is an ancestor of that node in the original document.

I could imagine using generate-id to do this. I wouldn't save the node per se, but an id to it and then use the id to get back to the node within the original document. The problem with this approach is that I can't ask for the node whose generate-id is such and such. I could go through the tree and find it, but I'm looking for a simpler, faster access method.

Does one exist?

Thanks in advance.

Upvotes: 2

Views: 200

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243529

Index every node of interest by its generate-id():

 <xsl:key name="kNodeById" match="node()"
  use="generate-id()"/>

and to get to the node by its id $vId:

key('kNodeById', $vId)

Upvotes: 1

Related Questions