1 //------------------------------------------------------------------------------
2 // <copyright file="CopyOfAction.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">[....]</owner>
6 //------------------------------------------------------------------------------
8 namespace System.Xml.Xsl.XsltOld {
9 using Res = System.Xml.Utils.Res;
11 using System.Diagnostics;
13 using System.Xml.XPath;
14 using MS.Internal.Xml.XPath;
16 internal class CopyOfAction : CompiledAction {
17 private const int ResultStored = 2;
18 private const int NodeSetCopied = 3;
20 private int selectKey = Compiler.InvalidQueryKey;
22 internal override void Compile(Compiler compiler) {
23 CompileAttributes(compiler);
24 CheckRequiredAttribute(compiler, selectKey != Compiler.InvalidQueryKey, "select");
28 internal override bool CompileAttribute(Compiler compiler) {
29 string name = compiler.Input.LocalName;
30 string value = compiler.Input.Value;
31 if (Ref.Equal(name, compiler.Atoms.Select)) {
32 this.selectKey = compiler.AddQuery(value);
41 internal override void Execute(Processor processor, ActionFrame frame) {
42 Debug.Assert(processor != null && frame != null);
44 switch (frame.State) {
46 Debug.Assert(frame.NodeSet != null);
47 Query query = processor.GetValueQuery(this.selectKey);
48 object result = query.Evaluate(frame.NodeSet);
50 if (result is XPathNodeIterator) {
51 // we cash this query because otherwise current() works incorrectly. Bug#382166.
52 // To be perfect we should use frame.NewNodeSet here
53 processor.PushActionFrame(CopyNodeSetAction.GetAction(), new XPathArrayIterator(query));
54 frame.State = NodeSetCopied;
58 XPathNavigator nav = result as XPathNavigator;
60 processor.PushActionFrame(CopyNodeSetAction.GetAction(), new XPathSingletonIterator(nav));
61 frame.State = NodeSetCopied;
65 string value = XmlConvert.ToXPathString(result);
66 if (processor.TextEvent(value)) {
69 frame.StoredOutput = value;
70 frame.State = ResultStored;
75 Debug.Assert(frame.StoredOutput != null);
76 processor.TextEvent(frame.StoredOutput);
81 Debug.Assert(frame.State == NodeSetCopied);