Example #1
0
        public static XElement XslIf(this XElement element, XPathExpr test)
        {
            XElement valueOfElement = element.XslGenericElement("if");

            valueOfElement.AddAttributeWithValue("test", test);
            return(valueOfElement);
        }
Example #2
0
        public XPathExpr GetGroupMembers(PSMComponent component, bool useCurrentInstanceVariable)
        {
            List <PSMComponent> groupMembers = new List <PSMComponent>();

            AddGroupMembersRecursive(component, ref groupMembers);

            List <XPathExpr> result = new List <XPathExpr>();

            foreach (PSMComponent psmComponent in groupMembers)
            {
                if (!psmComponent.ExistsInVersion(this.OldVersion))
                {
                    continue;
                }
                result.Add(this.GetRelativeXPath(psmComponent, useCurrentInstanceVariable));
            }

            if (result.Count == 0)
            {
                return(new XPathExpr("()"));
            }
            else
            {
                return(XPathExpr.ConcatWithPipeOperator(result));
            }
        }
Example #3
0
        public static XElement XslFunction(this XElement element, string name, string @as,
                                           params TemplateParameter[] parameters)
        {
            XElement templateElement = element.XslGenericElement("function");

            templateElement.AddAttributeWithValue("name", name);
            if (!string.IsNullOrEmpty(@as))
            {
                templateElement.AddAttributeWithValue("as", @as);
            }
            if (parameters != null)
            {
                foreach (TemplateParameter parameter in parameters)
                {
                    XElement param = templateElement.XslGenericElement("param");
                    param.AddAttributeWithValue("name", parameter.Name);
                    if (!string.IsNullOrEmpty(parameter.Type))
                    {
                        param.AddAttributeWithValue("as", parameter.Type);
                    }
                    if (!XPathExpr.IsNullOrEmpty(parameter.DefaultValue))
                    {
                        param.AddAttributeWithValue("select", parameter.DefaultValue);
                    }
                }
            }
            return(templateElement);
        }
Example #4
0
        public static XElement XslSequence(this XElement element, XPathExpr selectXPath)
        {
            XElement valueOfElement = element.XslGenericElement("sequence");

            valueOfElement.AddAttributeWithValue("select", selectXPath);
            return(valueOfElement);
        }
Example #5
0
        public static XElement XslForEachGroup(this XElement element, XPathExpr selectXPath)
        {
            XElement copyOfElement = element.XslGenericElement("for-each-group");

            copyOfElement.AddAttributeWithValue("select", selectXPath);
            return(copyOfElement);
        }
Example #6
0
        public static XElement XslForEach(this XElement element, XPathExpr selectXPath)
        {
            XElement forEachElement = element.XslGenericElement("for-each");

            forEachElement.AddAttributeWithValue("select", selectXPath);
            return(forEachElement);
        }
Example #7
0
        public static XElement XslCopyOf(this XElement element, XPathExpr selectXPath)
        {
            XElement copyOfElement = element.XslGenericElement("copy-of");

            copyOfElement.AddAttributeWithValue("select", selectXPath);
            return(copyOfElement);
        }
Example #8
0
        public static XElement XslWhen(this XElement element, XPathExpr test)
        {
            XElement option = element.XslGenericElement("when");

            option.AddAttributeWithValue("test", test);
            return(option);
        }
Example #9
0
 public bool HasPrefix(XPathExpr prefix)
 {
     if (prefix == null)
     {
         throw new ArgumentNullException("prefix");
     }
     return(this.ToString().StartsWith(prefix));
 }
Example #10
0
        //public XPathExpr NoCurrentGroup()
        //{
        //    return new XPathExpr(this._expr.Replace("/" + CurrentInstanceVariableExpr, String.Empty));
        //}

        #region equality members

        public bool Equals(XPathExpr other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            return(Equals(other._expr, _expr));
        }
Example #11
0
        public static XElement XslTemplate(this XElement element, XPathExpr matchXPath, params string[] parameters)
        {
            XElement templateElement = element.XslGenericElement("template");

            templateElement.AddAttributeWithValue("match", matchXPath);
            if (parameters != null)
            {
                foreach (string parameter in parameters)
                {
                    XElement param = templateElement.XslGenericElement("param");
                    param.AddAttributeWithValue("name", parameter);
                }
            }
            return(templateElement);
        }
Example #12
0
        public static XElement XslVariable(this XElement element, string name, XPathExpr selectXPath = null, string type = null)
        {
            XElement variableElement = element.XslGenericElement("variable");

            variableElement.AddAttributeWithValue("name", name);
            if (selectXPath != null)
            {
                variableElement.AddAttributeWithValue("select", selectXPath);
            }
            if (!string.IsNullOrEmpty(type))
            {
                variableElement.AddAttributeWithValue("as", type);
            }
            return(variableElement);
        }
Example #13
0
        private static XElement XslApplyTemplates(this XElement element, XPathExpr selectXPath, IEnumerable <TemplateParameter> parameters)
        {
            XElement applyTemplatesElement = element.XslGenericElement("apply-templates");

            applyTemplatesElement.AddAttributeWithValue("select", selectXPath);
            if (parameters != null)
            {
                foreach (TemplateParameter keyValuePair in parameters)
                {
                    XElement param = applyTemplatesElement.XslGenericElement("with-param");
                    param.AddAttributeWithValue("name", keyValuePair.Name);
                    param.AddAttributeWithValue("select", keyValuePair.Value);
                }
            }
            return(applyTemplatesElement);
        }
Example #14
0
        public XPathExpr GetRelativeXPath(IEnumerable <PSMComponent> expandedReference, bool useCurrentInstanceVariable)
        {
            IEnumerable <XPathExpr> result = from component in expandedReference select GetRelativeXPath(component, useCurrentInstanceVariable);

            return(XPathExpr.ConcatWithPipeOperator(result));
        }
Example #15
0
        public XPathExpr GetGroupDistinguisher(IEnumerable <PSMComponent> expandedReference)
        {
            IEnumerable <XPathExpr> result = from component in expandedReference select GetGroupDistinguisher(component);

            return(XPathExpr.ConcatWithPipeOperator(result));
        }
Example #16
0
        /*
         * useCurrentInstanceVariable is probably always false in the current version of the algorithm.
         */

        public XPathExpr GetRelativeXPath(PSMComponent node, bool useCurrentInstanceVariable, string currentInstanceVariableName = XDocumentXsltExtensions.ParamCurrentInstance)
        {
            PSMComponent closestExistingCurrentNode = CurrentNode.GetFirstAncestorOrSelfExistingInVersion(OldVersion).GetInVersion(OldVersion);
            PSMComponent closestExistingTargetNode  = node.GetFirstAncestorOrSelfExistingInVersion(OldVersion).GetInVersion(OldVersion);

            if (closestExistingTargetNode == null)
            {
                throw new InvalidOperationException();
            }

            if (closestExistingCurrentNode == null)
            {
                return(new XPathExpr(closestExistingTargetNode.XPath));
            }

            XPathExpr currentNodeAbsoluteXPath = new XPathExpr(closestExistingCurrentNode.GetInVersion(OldVersion).XPath);
            // /A/R
            XPathExpr targetNodeAbsoluteXPath = new XPathExpr(closestExistingTargetNode.GetInVersion(OldVersion).XPath);

            // /A/R/B/z

            if (targetNodeAbsoluteXPath.HasPrefix(currentNodeAbsoluteXPath) && targetNodeAbsoluteXPath != currentNodeAbsoluteXPath)
            {
                string withoutPrefix = targetNodeAbsoluteXPath.ToString().Substring(currentNodeAbsoluteXPath.ToString().Length);
                while (withoutPrefix[0].IsAmong('/', '@'))
                {
                    withoutPrefix = withoutPrefix.Substring(1);
                }

                string nextStep;
                if (withoutPrefix.IndexOf('/') == -1)
                {
                    nextStep = withoutPrefix.Substring(0, withoutPrefix.Length);
                }
                else
                {
                    nextStep = withoutPrefix.Substring(0, withoutPrefix.IndexOf('/'));
                }

                string afterNextStep = withoutPrefix.Substring(nextStep.Length);

                XPathExpr result;

                if (useCurrentInstanceVariable)
                {
                    result = new XPathExpr(string.Format("${3}[name() = '{0}']{1}{2}", nextStep, string.IsNullOrEmpty(afterNextStep) ? string.Empty : "/", afterNextStep, currentInstanceVariableName));
                }
                else
                {
                    result = new XPathExpr(string.Format("{0}{1}{2}", nextStep, string.IsNullOrEmpty(afterNextStep) ? string.Empty : "/", afterNextStep));
                }

                return(result);
            }
            else if (targetNodeAbsoluteXPath == currentNodeAbsoluteXPath)
            {
                return(new XPathExpr("."));
            }
            else
            {
                // find the uppermost common node
                PSMAssociationMember nearestCommonAncestor = closestExistingCurrentNode.GetNearestCommonAncestor(closestExistingTargetNode);
                if (nearestCommonAncestor != null)
                {
                    string commonPath = nearestCommonAncestor.XPath;
                    Debug.Assert(targetNodeAbsoluteXPath.HasPrefix(new XPathExpr(commonPath)));
                    Debug.Assert(currentNodeAbsoluteXPath.HasPrefix(new XPathExpr(commonPath)));
                    string fromCommonToTarget  = targetNodeAbsoluteXPath.ToString().Replace(commonPath, string.Empty);
                    string fromCommonToCurrent = currentNodeAbsoluteXPath.ToString().Replace(commonPath, string.Empty);
                    string stepsUp             = string.Empty;

                    foreach (char c in fromCommonToCurrent)
                    {
                        if (c == '/')
                        {
                            stepsUp += "../";
                        }
                    }

                    if (fromCommonToTarget.StartsWith("/"))
                    {
                        fromCommonToTarget = fromCommonToTarget.Substring(1);
                    }


                    string joined = string.Format("{0}{1}", stepsUp, fromCommonToTarget);
                    if (joined.EndsWith("/"))
                    {
                        joined = joined.Substring(0, joined.Length - 1);
                    }
                    return(new XPathExpr(joined));
                }
                else
                {
                    return(new XPathExpr(closestExistingTargetNode.XPath));
                }
            }
        }
Example #17
0
 public static TemplateParameter CreateCurrentInstanceParameterCall(XPathExpr select)
 {
     return(new TemplateParameter(ParamCurrentInstance, select));
 }
Example #18
0
 public XPathExpr(XPathExpr expression)
 {
     _expr = expression._expr;
 }
Example #19
0
 public TemplateParameter(string name, XPathExpr value)
     : this()
 {
     Name  = name;
     Value = value;
 }
Example #20
0
 public static bool IsNullOrEmpty(XPathExpr expr)
 {
     return(expr == null || expr.IsEmpty());
 }
Example #21
0
 public static XElement XslApplyTemplates(this XElement element, XPathExpr selectXPath, params TemplateParameter[] parameters)
 {
     return(XslApplyTemplates(element, selectXPath, (IEnumerable <TemplateParameter>)parameters));
 }