开发者

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 th开发者_JAVA百科en 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.


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜