public XPathExpr ToXPath() { string _p = String.Empty; for (int i = this.Count - 1; i >= 0; i--) { PSMElement psmElement = this[i]; if (psmElement.ModelsElement()) { _p += "/" + XsltTemplateNameManager.GetElementNameForSignificantElement(psmElement); } else if (psmElement is PSMAttribute) { _p += "/@" + ((PSMAttribute)psmElement).AliasOrName; } } return(new XPathExpr(_p)); }
/// <summary> /// Performs <see cref="GroupAwareProjectXPath"/> and substitutes steps in the result path according /// to structural representative information. (So the path is relative to the structural representative) /// </summary> /// <param name="context">The generator context.</param> /// <param name="element">The element.</param> /// <param name="structuralRepresentativeReplacement">The structural representative replacement.</param> /// <returns></returns> public static XPathExpr GroupAwareProjectXPathWithSRSubstitution(XsltGeneratorContext context, PSMElement element, IFromStructuralRepresentative structuralRepresentativeReplacement) { XPathExpr expr; if (structuralRepresentativeReplacement != null) { var cp = context.ProcessedPath; //if (PSMTreeIterator.AreInTheSamePSMTree(structuralRepresentativeReplacement.RepresentedPSMClass, structuralRepresentativeReplacement.StructuralRepresentative)) PSMElement representedOldAnc = PSMTreeIterator.GetSignificantAncestorOrSelf((PSMClass)structuralRepresentativeReplacement.RepresentedPSMClass.GetInVersion(context.ChangeSet.OldVersion)); PSMElement structuralRepresentativeOldAnc = PSMTreeIterator.GetSignificantAncestorOrSelf((PSMClass)structuralRepresentativeReplacement.StructuralRepresentative.GetInVersion(context.ChangeSet.OldVersion)); if (representedOldAnc != null) { context.ProcessedPath = GetXPathForNode(representedOldAnc, context.ChangeSet.OldVersion); } else { context.ProcessedPath = new XPathExpr("<virt-root>"); if (context.InGroup) { context.ProcessedPath = context.ProcessedPath.Append("/$cg"); } } string from = representedOldAnc != null?XsltTemplateNameManager.GetElementNameForSignificantElement(representedOldAnc) : null; string to = structuralRepresentativeOldAnc != null?XsltTemplateNameManager.GetElementNameForSignificantElement(structuralRepresentativeOldAnc) : null; XPathExpr e = null; if (from != null && to != null && !(context.ProcessedPath.ToString().EndsWith(from) && cp.ToString().EndsWith(to))) { e = ProjectXPath(cp, context.ProcessedPath, false); if (!XPathExpr.IsNullOrEmpty(e) && !String.IsNullOrEmpty(to) && !String.IsNullOrEmpty(from)) { if (e.ToString().Contains(from)) { e = new XPathExpr(e.ToString().Replace(from, to)); } } } expr = GroupAwareProjectXPath(context, element, context.ChangeSet.OldVersion); if (!XPathExpr.IsNullOrEmpty(e)) { // ReSharper disable PossibleNullReferenceException expr = e.Append("/" + expr); } // ReSharper restore PossibleNullReferenceException context.ProcessedPath = cp; } else { expr = GroupAwareProjectXPath(context, element, context.ChangeSet.OldVersion); } return(expr); }