bug 259575 - XPath XML Element assistance and general cleanup and refactoring.
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ElementContentAssistRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/AbstractXMLElementContentAssistRequest.java
similarity index 65%
rename from bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ElementContentAssistRequest.java
rename to bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/AbstractXMLElementContentAssistRequest.java
index 4df8b40..519125c 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ElementContentAssistRequest.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/AbstractXMLElementContentAssistRequest.java
@@ -1,13 +1,3 @@
-/*******************************************************************************
- *Copyright (c) 2008 Standards for Technology in Automotive Retail and others.
- *All rights reserved. This program and the accompanying materials
- *are made available under the terms of the Eclipse Public License v1.0
- *which accompanies this distribution, and is available at
- *http://www.eclipse.org/legal/epl-v10.html
- *
- *Contributors:
- *    David Carver (STAR) - bug 244978 - initial API and implementation
- *******************************************************************************/
 package org.eclipse.wst.xsl.ui.internal.contentassist;
 
 import java.util.ArrayList;
@@ -16,7 +6,6 @@
 import java.util.Vector;
 
 import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
 import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
@@ -26,8 +15,9 @@
 import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
 import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
 import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction;
+import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper;
 import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
 import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
 import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
 import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
@@ -41,25 +31,21 @@
 import org.w3c.dom.NodeList;
 
 /**
- * This class provides content assistance proposals outside of the XSL namespace.  Normal
- * XML editor content assistance only provides proposals for items within the same namespace
- * or if an element has children elements.   This class extends this functionality by checking
- * for the first XSL ancestor and uses that to determine what proposals should be
- * provided in the way of xsl elements.
+ * Adopters can extend this class to implement their own content assistance for Element
+ * proposals using the XML Content Model.
  * 
  * @author David Carver
- * @since 1.0
+ *
  */
-public class ElementContentAssistRequest extends
-		AbstractXSLContentAssistRequest {
+public abstract class AbstractXMLElementContentAssistRequest extends AbstractXSLContentAssistRequest {
 
-	private XSLContentModelGenerator contentModel;
-	private static final String XPATH_FIRST_XSLANCESTOR_NODE = "ancestor::xsl:*[1]";
-	private MarkupTagInfoProvider infoProvider = null;
-
+	protected static final String XPATH_FIRST_XSLANCESTOR_NODE = "ancestor::xsl:*[1]";
+	protected MarkupTagInfoProvider infoProvider = null;
+	protected XSLContentModelGenerator contentModel;
+	
 	/**
+	 *
 	 * @param node
-	 * @param parent
 	 * @param documentRegion
 	 * @param completionRegion
 	 * @param begin
@@ -67,74 +53,90 @@
 	 * @param filter
 	 * @param textViewer
 	 */
-	public ElementContentAssistRequest(Node node,
+	public AbstractXMLElementContentAssistRequest(Node node,
 			IStructuredDocumentRegion documentRegion,
 			ITextRegion completionRegion, int begin, int length, String filter,
 			ITextViewer textViewer) {
-		super(node, documentRegion, completionRegion, begin, length,
-				filter, textViewer);
-		contentModel = new XSLContentModelGenerator();
+		super(node, documentRegion, completionRegion, begin, length, filter, textViewer);
 	}
 
-	/**
-	 * Provides a list of possible proposals for the XSL Elements within the current
-	 * scope.
-	 */
-	@Override
-	public ArrayList<ICompletionProposal> getCompletionProposals() {
-
-		if (region.getType() == DOMRegionContext.XML_TAG_OPEN) {
-			computeTagOpenProposals();
-		} else if (region.getType() == DOMRegionContext.XML_TAG_NAME) {
-			computeTagNameProposals();
-		}
-		return getAllCompletionProposals();
+	protected Iterator<CMNode> getAvailableContentNodes(IDOMDocument domDocument, Node ancestorNode, int includeOptions) {
+		ModelQuery modelQuery = ModelQueryUtil.getModelQuery(domDocument);
+		CMElementDeclaration cmElementDec = modelQuery.getCMElementDeclaration((Element)ancestorNode);
+		List <CMNode> cmNodeList = modelQuery.getAvailableContent((Element)ancestorNode, cmElementDec, includeOptions);
+		Iterator <CMNode> cmNodeIt = cmNodeList.iterator();
+		return cmNodeIt;
 	}
 
-	/**
-	 * Calculate proposals for open content regions.
-	 */
-	protected void computeTagOpenProposals() {
-
-		if (replacementBeginPosition == documentRegion.getStartOffset(region)) {
-			if (node.getNodeType() == Node.ELEMENT_NODE) {
-				// at the start of an existing tag, right before the '<'
-				computeTagNameProposals();
+	protected CustomCompletionProposal createProposal(String proposedText, String additionalInfo, int offset,
+			Image image, int startLength) {
+				CustomCompletionProposal proposal = new CustomCompletionProposal(
+						proposedText, offset, 0, startLength + proposedText.length(), 
+						image, proposedText, null, additionalInfo, 0);
+				return proposal;
 			}
-		} else {
-			// within the white space
-			ITextRegion name = getNameRegion(((IDOMNode) node)
-					.getStartStructuredDocumentRegion());
-			if ((name != null)
-					&& ((documentRegion.getStartOffset(name) <= replacementBeginPosition) && (documentRegion
-							.getEndOffset(name) >= replacementBeginPosition))) {
-				// replace the existing name
-				replacementBeginPosition = documentRegion.getStartOffset(name);
-				replacementLength = name.getTextLength();
-			} else {
-				// insert a valid new name, or possibly an end tag
-				// addEndTagProposals(contentAssistRequest);
-				setReplacementLength(0);
-			}
-			addTagNameProposals(getElementPosition(node));
+
+	protected Image getCMNodeImage(CMNode cmNode) {
+		Image image = CMImageUtil.getImage(cmNode);
+		if (image == null) {
+			image = XMLEditorPluginImageHelper
+					.getInstance()
+					.getImage(
+							XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
 		}
+		return image;
+	}
+
+	protected String getRequiredName(Node ownerNode, CMNode cmnode) {
+		if (ownerNode != null) {
+			return DOMNamespaceHelper.computeName(cmnode, ownerNode, null);
+		}
+		return cmnode.getNodeName();
 	}
 
 	/**
-	 * Calculates the proposals for the XML Tag Name Region.
+	 * Retrieves cmnode's documentation to display in the completion proposal's
+	 * additional info. If no documentation exists for cmnode, try displaying
+	 * parentOrOwner's documentation
+	 * 
+	 * String any documentation information to display for cmnode.
+	 * <code>null</code> if there is nothing to display.
 	 */
-	protected void computeTagNameProposals() {
-		// completing the *first* tag in "<tagname1 |<tagname2"
-		
-		// Ignore attributes
-		if (inAttributeRegion()) {
-			return;
+	protected String getAdditionalInfo(CMNode parentOrOwner, CMNode cmnode) {
+		String addlInfo = null;
+	
+		if (cmnode == null) {
+			if (Debug.displayWarnings) {
+				new IllegalArgumentException("Null declaration!").printStackTrace(); //$NON-NLS-1$
+			}
+			return null;
 		}
-		
-		IDOMNode actualNode = (IDOMNode) node;
-		addTagNameProposals(this.getElementPosition(node));
-		// addEndTagNameProposals();
+	
+		addlInfo = getInfoProvider().getInfo(cmnode);
+		if ((addlInfo == null) && (parentOrOwner != null)) {
+			addlInfo = getInfoProvider().getInfo(parentOrOwner);
+		}
+		return addlInfo;
+	}
 
+	/**
+	 * Gets the infoProvider.
+	 * 
+	 * fInfoProvider and if fInfoProvider was <code>null</code> create a new
+	 * instance
+	 */
+	protected MarkupTagInfoProvider getInfoProvider() {
+		if (infoProvider == null) {
+			infoProvider = new MarkupTagInfoProvider();
+		}
+		return infoProvider;
+	}
+
+	protected boolean beginsWith(String aString, String prefix) {
+		if ((aString == null) || (prefix == null)) {
+			return true;
+		}
+		return aString.toLowerCase().startsWith(prefix.toLowerCase());
 	}
 
 	/**
@@ -151,7 +153,7 @@
 	 * @param position
 	 */
 	protected void addTagNameProposals(int position) {
-
+	
 		Node ancestorNode = null;
 		try {
 			ancestorNode = XSLTXPathHelper.selectSingleNode(getNode(),
@@ -159,9 +161,9 @@
 		} catch (Exception ex) {
 			return;
 		}
-
+	
 		List<CMNode> cmnodes = null;
-
+	
 		if (ancestorNode.getNodeType() == Node.ELEMENT_NODE) {
 			cmnodes = getAvailableChildElementDeclarations(
 					(Element) ancestorNode, 0);
@@ -182,11 +184,11 @@
 					// only add proposals for the child element's that begin
 					// with the matchstring
 					String proposedText = null;
-
+	
 					proposedText = contentModel.getRequiredName(ancestorNode,
 							elementDecl);
 					int cursorAdjustment = proposedText.length();
-
+	
 					if (elementDecl instanceof CMElementDeclaration) {
 						CMElementDeclaration ed = (CMElementDeclaration) elementDecl;
 						if (ed.getContentType() == CMElementDeclaration.EMPTY) {
@@ -201,7 +203,7 @@
 							// only return the rest of the tag
 							proposedText = sb.toString().substring(1);
 							cursorAdjustment = getCursorPositionForProposedText(proposedText);
-
+	
 						}
 					}
 					if (beginsWith(proposedText, matchString)) {
@@ -225,10 +227,9 @@
 				}
 			}
 		}
-
+	
 	}
 
-
 	/** Returns a list of CMNodes that are available within this parent context
 	 * Given the grammar shown below and a snippet of XML code (where the '|'
 	 * indicated the cursor position)
@@ -245,43 +246,42 @@
 	 */
 	protected List<CMNode> getAvailableChildElementDeclarations(Element parent,
 			int childPosition) {
-		List modelQueryActions = getAvailableChildrenAtIndex(parent,
-				childPosition, ModelQuery.VALIDITY_NONE);
-		Iterator iterator = modelQueryActions.iterator();
-		List<CMNode> cmnodes = new Vector();
-		while (iterator.hasNext()) {
-			ModelQueryAction action = (ModelQueryAction) iterator.next();
-			if ((childPosition < 0)
-					|| (((action.getStartIndex() <= childPosition) && (childPosition <= action
-							.getEndIndex())))) {
-				CMNode actionCMNode = action.getCMNode();
-				if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
-					cmnodes.add(actionCMNode);
+				List modelQueryActions = getAvailableChildrenAtIndex(parent,
+						childPosition, ModelQuery.VALIDITY_NONE);
+				Iterator iterator = modelQueryActions.iterator();
+				List<CMNode> cmnodes = new Vector();
+				while (iterator.hasNext()) {
+					ModelQueryAction action = (ModelQueryAction) iterator.next();
+					if ((childPosition < 0)
+							|| (((action.getStartIndex() <= childPosition) && (childPosition <= action
+									.getEndIndex())))) {
+						CMNode actionCMNode = action.getCMNode();
+						if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
+							cmnodes.add(actionCMNode);
+						}
+					}
 				}
+				return cmnodes;
 			}
-		}
-		return cmnodes;
-	}
 
-	// returns a list of ModelQueryActions
 	protected List getAvailableChildrenAtIndex(Element parent, int index,
 			int validityChecking) {
-		List list = new ArrayList();
-		CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
-		if (parentDecl != null) {
-			ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent
-					.getOwnerDocument());
-			// taken from ActionManagers
-			// int editMode = modelQuery.getEditMode();
-			int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
-			int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES
-					| ModelQuery.INCLUDE_SEQUENCE_GROUPS
-					: ModelQuery.INCLUDE_CHILD_NODES;
-			modelQuery.getInsertActions(parent, parentDecl, index, ic,
-					validityChecking, list);
-		}
-		return list;
-	}
+				List list = new ArrayList();
+				CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
+				if (parentDecl != null) {
+					ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent
+							.getOwnerDocument());
+					// taken from ActionManagers
+					// int editMode = modelQuery.getEditMode();
+					int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
+					int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES
+							| ModelQuery.INCLUDE_SEQUENCE_GROUPS
+							: ModelQuery.INCLUDE_CHILD_NODES;
+					modelQuery.getInsertActions(parent, parentDecl, index, ic,
+							validityChecking, list);
+				}
+				return list;
+			}
 
 	protected CMElementDeclaration getCMElementDeclaration(Node node) {
 		CMElementDeclaration result = null;
@@ -300,13 +300,13 @@
 		if (parent == null) {
 			return 0;
 		}
-
+	
 		NodeList children = parent.getChildNodes();
 		if (children == null) {
 			return 0;
 		}
 		int count = 0;
-
+	
 		for (int i = 0; i < children.getLength(); i++) {
 			if (children.item(i) == child) {
 				return count;
@@ -319,51 +319,6 @@
 	}
 
 	/**
-	 * Retreives cmnode's documentation to display in the completion proposal's
-	 * additional info. If no documentation exists for cmnode, try displaying
-	 * parentOrOwner's documentation
-	 * 
-	 * String any documentation information to display for cmnode.
-	 * <code>null</code> if there is nothing to display.
-	 */
-	protected String getAdditionalInfo(CMNode parentOrOwner, CMNode cmnode) {
-		String addlInfo = null;
-
-		if (cmnode == null) {
-			if (Debug.displayWarnings) {
-				new IllegalArgumentException("Null declaration!").printStackTrace(); //$NON-NLS-1$
-			}
-			return null;
-		}
-
-		addlInfo = getInfoProvider().getInfo(cmnode);
-		if ((addlInfo == null) && (parentOrOwner != null)) {
-			addlInfo = getInfoProvider().getInfo(parentOrOwner);
-		}
-		return addlInfo;
-	}
-
-	/**
-	 * Gets the infoProvider.
-	 * 
-	 * fInfoProvider and if fInfoProvider was <code>null</code> create a new
-	 * instance
-	 */
-	public MarkupTagInfoProvider getInfoProvider() {
-		if (infoProvider == null) {
-			infoProvider = new MarkupTagInfoProvider();
-		}
-		return infoProvider;
-	}
-
-	protected boolean beginsWith(String aString, String prefix) {
-		if ((aString == null) || (prefix == null)) {
-			return true;
-		}
-		return aString.toLowerCase().startsWith(prefix.toLowerCase());
-	}
-
-	/**
 	 * This is the position the cursor should be in after the proposal is
 	 * applied
 	 * 
@@ -371,7 +326,7 @@
 	 * @return the position the cursor should be in after the proposal is
 	 *         applied
 	 */
-	private int getCursorPositionForProposedText(String proposedText) {
+	protected int getCursorPositionForProposedText(String proposedText) {
 		int cursorAdjustment;
 		cursorAdjustment = proposedText.indexOf("\"\"") + 1; //$NON-NLS-1$
 		// otherwise, after the first tag
@@ -381,7 +336,7 @@
 		if (cursorAdjustment == 0) {
 			cursorAdjustment = proposedText.length() + 1;
 		}
-
+	
 		return cursorAdjustment;
 	}
 
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java
index 76f4c67..2b3fba0 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java
@@ -96,7 +96,7 @@
 		adjustXPathStart();
 		
 		int offset = getReplacementBeginPosition();
-		IDOMAttr attrNode = (IDOMAttr)((IDOMElement)getNode()).getAttributeNode("select");
+		IDOMAttr attrNode = getAttribute("select");
 		
 		this.matchString = extractXPathMatchString(attrNode, getRegion(), getReplacementBeginPosition());
 		
@@ -104,6 +104,11 @@
 
 		return  getAllCompletionProposals();
     }
+
+
+	private IDOMAttr getAttribute(String attrName) {
+		return (IDOMAttr)((IDOMElement)getNode()).getAttributeNode(attrName);
+	}
 	
 	
 
@@ -145,6 +150,7 @@
 
 
 	protected void addSelectProposals(Element rootElement, int offset) {
+			addContentModelProposals();
 			addGlobalProposals(rootElement, offset);
 			addLocalProposals(getNode(), offset);
 			addTemplates(TemplateContextTypeIdsXPath.AXIS, offset);
@@ -152,6 +158,16 @@
 			addTemplates(TemplateContextTypeIdsXPath.CUSTOM, offset);
 			addTemplates(TemplateContextTypeIdsXPath.OPERATOR, offset);
 	}
+
+
+	private void addContentModelProposals() {
+		AbstractXMLElementContentAssistRequest xpathXMLproposals =
+			new XPathElementContentAssist(node, documentRegion, getRegion(), getReplacementBeginPosition(), getReplacementLength(), getMatchString(), textViewer);
+		ArrayList<ICompletionProposal> xmlProposals = xpathXMLproposals.getCompletionProposals();
+		proposals.addAll(xmlProposals);
+	}
+	
+	
 	
 	/**
 	 * Adds XPath related templates to the list of proposals
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XPathElementContentAssist.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XPathElementContentAssist.java
new file mode 100644
index 0000000..f779329
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XPathElementContentAssist.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ *Copyright (c) 2008 Standards for Technology in Automotive Retail and others.
+ *All rights reserved. This program and the accompanying materials
+ *are made available under the terms of the Eclipse Public License v1.0
+ *which accompanies this distribution, and is available at
+ *http://www.eclipse.org/legal/epl-v10.html
+ *
+ *Contributors:
+ *    David Carver (STAR) - bug 244978 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.ui.internal.contentassist;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
+import org.eclipse.wst.xml.ui.internal.taginfo.MarkupTagInfoProvider;
+import org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper;
+import org.eclipse.wst.xsl.ui.internal.XSLUIPlugin;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * This class provides XML Element proposals within XPath related items like
+ * select, test, and match attributes.  This will leverage an ContentModel that
+ * has been loaded and try to provide all available XML elements that could be used.
+ * It should be enhanced to know the elements to be used based on information from
+ * the XPath.
+ * 
+ * @author David Carver
+ * @since 1.0
+ */
+public class XPathElementContentAssist extends
+		AbstractXMLElementContentAssistRequest {
+
+	/**
+	 * @param node
+	 * @param parent
+	 * @param documentRegion
+	 * @param completionRegion
+	 * @param begin
+	 * @param length
+	 * @param filter
+	 * @param textViewer
+	 */
+	public XPathElementContentAssist(Node node,
+			IStructuredDocumentRegion documentRegion,
+			ITextRegion completionRegion, int begin, int length, String filter,
+			ITextViewer textViewer) {
+		super(node, documentRegion, completionRegion, begin, length,
+				filter, textViewer);
+	}
+
+	/**
+	 * Provides a list of possible proposals for the XML Elements within the current
+	 * scope.  This leverages the ContentModel that was loaded by the XML Catalog, 
+	 * Custom Resolver, or the inferred grammar.
+	 */
+	@Override
+	public ArrayList<ICompletionProposal> getCompletionProposals() {
+		IDOMDocument domDocument = (IDOMDocument) node.getOwnerDocument();
+		
+		getXPathXMLElementProposals(domDocument);
+		
+		
+		return getAllCompletionProposals();
+	}
+
+	private void getXPathXMLElementProposals(IDOMDocument domDocument) {
+		try {
+			Node ancestorNode = XSLTXPathHelper.selectSingleNode(getNode(),
+					XPATH_FIRST_XSLANCESTOR_NODE);
+			
+			Iterator<CMNode> cmNodeIt = getAvailableContentNodes(domDocument,
+					ancestorNode, ModelQuery.INCLUDE_CHILD_NODES);
+			
+			createXPathXMLProposals(ancestorNode, cmNodeIt);
+
+		} catch (Exception ex) {
+			XSLUIPlugin.log(ex);
+		}
+	}
+
+	private void createXPathXMLProposals(Node ancestorNode,
+			Iterator<CMNode> cmNodeIt) {
+		while (cmNodeIt.hasNext()) {
+			CMNode cmNode = cmNodeIt.next();
+			String proposedText = getRequiredName(ancestorNode, cmNode);
+			if (!(proposedText.contains("xsl:") || proposedText.contains("xslt:"))) {
+				int offset = getCursorPosition();
+				Image image = getCMNodeImage(cmNode);
+				int startLength = getCursorPosition() - offset;
+				String additionalInfo = getInfoProvider().getInfo(cmNode);
+				
+				if (matchString.length() > 0) {
+					if (proposedText.startsWith(matchString)) {
+						CustomCompletionProposal proposal = createProposal(
+								proposedText, additionalInfo, offset, image, startLength);
+						addProposal(proposal);
+					}
+				} else {
+					CustomCompletionProposal proposal = createProposal(
+							proposedText, additionalInfo, offset, image, startLength);
+					addProposal(proposal);
+				}					
+			}
+		}
+	}
+
+}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java
index b2c400f..9c1b720 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java
@@ -133,7 +133,7 @@
 
 	private ArrayList<ICompletionProposal> getAdditionalXSLElementProposals() {
 		if (!XSLCore.isXSLNamespace(xmlNode)) {
-			additionalProposals = new ElementContentAssistRequest(xmlNode,
+			additionalProposals = new XSLElementContentAssistRequest(xmlNode,
 					sdRegion, completionRegion, cursorPosition, 0, matchString,
 					textViewer).getCompletionProposals();
 		}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLElementContentAssistRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLElementContentAssistRequest.java
new file mode 100644
index 0000000..f0245dc
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLElementContentAssistRequest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ *Copyright (c) 2008 Standards for Technology in Automotive Retail and others.
+ *All rights reserved. This program and the accompanying materials
+ *are made available under the terms of the Eclipse Public License v1.0
+ *which accompanies this distribution, and is available at
+ *http://www.eclipse.org/legal/epl-v10.html
+ *
+ *Contributors:
+ *    David Carver (STAR) - bug 244978 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.ui.internal.contentassist;
+
+import java.util.ArrayList;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.util.Debug;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.eclipse.wst.xml.ui.internal.taginfo.MarkupTagInfoProvider;
+import org.eclipse.wst.xsl.ui.internal.contentassist.contentmodel.XSLContentModelGenerator;
+import org.w3c.dom.Node;
+
+/**
+ * This class provides content assistance proposals outside of the XSL namespace.  Normal
+ * XML editor content assistance only provides proposals for items within the same namespace
+ * or if an element has children elements.   This class extends this functionality by checking
+ * for the first XSL ancestor and uses that to determine what proposals should be
+ * provided in the way of xsl elements.
+ * 
+ * @author David Carver
+ * @since 1.0
+ */
+public class XSLElementContentAssistRequest extends
+		AbstractXMLElementContentAssistRequest {
+
+	/**
+	 * @param node
+	 * @param parent
+	 * @param documentRegion
+	 * @param completionRegion
+	 * @param begin
+	 * @param length
+	 * @param filter
+	 * @param textViewer
+	 */
+	public XSLElementContentAssistRequest(Node node,
+			IStructuredDocumentRegion documentRegion,
+			ITextRegion completionRegion, int begin, int length, String filter,
+			ITextViewer textViewer) {
+		super(node, documentRegion, completionRegion, begin, length,
+				filter, textViewer);
+		contentModel = new XSLContentModelGenerator();
+	}
+
+	/**
+	 * Provides a list of possible proposals for the XSL Elements within the current
+	 * scope.
+	 */
+	@Override
+	public ArrayList<ICompletionProposal> getCompletionProposals() {
+
+		if (region.getType() == DOMRegionContext.XML_TAG_OPEN) {
+			computeTagOpenProposals();
+		} else if (region.getType() == DOMRegionContext.XML_TAG_NAME) {
+			computeTagNameProposals();
+		}
+		return getAllCompletionProposals();
+	}
+
+	/**
+	 * Calculate proposals for open content regions.
+	 */
+	protected void computeTagOpenProposals() {
+
+		if (replacementBeginPosition == documentRegion.getStartOffset(region)) {
+			if (node.getNodeType() == Node.ELEMENT_NODE) {
+				// at the start of an existing tag, right before the '<'
+				computeTagNameProposals();
+			}
+		} else {
+			// within the white space
+			ITextRegion name = getNameRegion(((IDOMNode) node)
+					.getStartStructuredDocumentRegion());
+			if ((name != null)
+					&& ((documentRegion.getStartOffset(name) <= replacementBeginPosition) && (documentRegion
+							.getEndOffset(name) >= replacementBeginPosition))) {
+				// replace the existing name
+				replacementBeginPosition = documentRegion.getStartOffset(name);
+				replacementLength = name.getTextLength();
+			} else {
+				// insert a valid new name, or possibly an end tag
+				// addEndTagProposals(contentAssistRequest);
+				setReplacementLength(0);
+			}
+			addTagNameProposals(getElementPosition(node));
+		}
+	}
+
+	/**
+	 * Calculates the proposals for the XML Tag Name Region.
+	 */
+	protected void computeTagNameProposals() {
+		// completing the *first* tag in "<tagname1 |<tagname2"
+		
+		// Ignore attributes
+		if (inAttributeRegion()) {
+			return;
+		}
+		
+		IDOMNode actualNode = (IDOMNode) node;
+		addTagNameProposals(this.getElementPosition(node));
+		// addEndTagNameProposals();
+
+	}
+
+}
diff --git a/docs/org.eclipse.wst.xsl.doc/toc.xml b/docs/org.eclipse.wst.xsl.doc/toc.xml
index 4bf83d8..524b231 100644
--- a/docs/org.eclipse.wst.xsl.doc/toc.xml
+++ b/docs/org.eclipse.wst.xsl.doc/toc.xml
@@ -1 +1 @@
-<toc topic="html/index.html" label="XSL Tools User Documentation"><topic href="html/introduction/gettingstarted.html" label="Getting Started"></topic><topic href="html/concepts/concepts.html" label="XSLT Concepts"><topic href="html/concepts/concepts.html#ResucingXSLT" label="Rescuing XSLT From Niche Status"><topic href="html/concepts/concepts.html#N10034" label="The Problem"></topic><topic href="html/concepts/concepts.html#N1005A" label="The Solution"></topic><topic href="html/concepts/concepts.html#N10081" label="Queries"><topic href="html/concepts/concepts.html#N1008F" label="xsl:for-each"></topic><topic href="html/concepts/concepts.html#N1009B" label="xsl:if"></topic><topic href="html/concepts/concepts.html#N100A5" label="xsl:choose"></topic></topic><topic href="html/concepts/concepts.html#N100AF" label="Conclusion"></topic></topic><topic href="html/concepts/resources.html" label="Resources"></topic></topic><topic href="html/editor/xsleditor.html" label="XSL Editing"><topic href="html/editor/xsleditor.html#Validation" label="Validation"></topic><topic href="html/editor/xsleditor_contentassist.html" label="Content Assist"><topic href="html/editor/xsleditor_contentassist.html#ed_XSLProposals" label="XSLT Element Proposals"></topic><topic href="html/ch03s02s02.html" label="Select, Test, and Match Attributes"></topic><topic href="html/ch03s02s03.html" label="Exclude-Result-Prefixes"></topic><topic href="html/ch03s02s04.html" label="Mode attribute assistance"></topic><topic href="html/ch03s02s05.html" label="Named Template Assistance"></topic><topic href="html/ch03s02s06.html" label="Call-Template Assistance"></topic><topic href="html/ch03s02s07.html" label="Include and Import href Assistance"></topic></topic><topic href="html/editor/xsleditor_templates.html" label="Templates"><topic href="html/editor/xsleditor_templates.html#N101CC" label="XPath Templates"></topic></topic><topic href="html/editor/xsleditor_coloring.html" label="XSLT Syntax Coloring"></topic><topic href="html/editor/xsleditor_markers.html" label="XSLT Markers and Annotations"><topic href="html/editor/xsleditor_markers.html#xsltOverRide" label="Template Override"></topic></topic><topic href="html/editor/xsleditor_debugging.html" label="XSL Debugging"></topic><topic href="html/editor/xsleditor_debugging.html" label="Navigation"></topic></topic><topic href="html/launching/launching.html" label="XSL Launching and Debugging"><topic href="html/launching/launching.html#XSLLaunch" label="XSL Launching"></topic><topic href="html/launching/debugging.html" label="XSLT Debugging"><topic href="html/launching/debugging.html#DebugGettingStarted" label="Starting a Debug Session"></topic><topic href="html/launching/debugging_common.html" label="Common Debugging Operations"><topic href="html/launching/debugging_common.html#XSLDebugResultView" label="Result View"></topic><topic href="html/launching/debugging_variablesview.html" label="Variables View"></topic></topic><topic href="html/launching/debugging_processors.html" label="XSLT Processor Specific Support"><topic href="html/launching/debugging_processors.html#XSLDebugXalan" label="XSL Debugging with Xalan"></topic></topic></topic></topic><topic href="html/preferences/xslpreferences.html" label="XSL Tools Preferences"><topic href="html/preferences/xslpreferences.html#XSLFeatures" label="Features"></topic><topic href="html/preferences/xslprocessors.html" label="Installed Processors"></topic><topic href="html/preferences/xsloutputproperties.html" label="Output Properties"></topic><topic href="html/preferences/xpathtemplates.html" label="XPath Templates"><topic href="html/preferences/xpathtemplates.html#XPathTemplateNew" label="Creating New Templates"></topic><topic href="html/preferences/xpathimport.html" label="Import XPath Templates"></topic><topic href="html/preferences/xpathexport.html" label="Import XPath Templates"></topic></topic><topic href="html/preferences/validation.html" label="Project Validation Preferences"></topic><topic href="html/preferences/syntaxColoring.html" label="XSLT Syntax Coloring"></topic></topic><topic href="html/general/general.html" label="General"><topic href="html/general/general.html#XInclude" label="XInclude"></topic></topic><topic href="html/samples/samples.html" label="XSL Tooling Samples"><topic href="html/samples/samples.html#EclipseHelp" label="Eclipse Help"><topic href="html/samples/samples.html#DocbookEclipseHelp" label="Creating Eclipse Help with Docbook and XSL Tools"></topic><topic href="html/samples/samples.html#DITAEclipseHelp" label="Creating Eclipse Help with DITA and XSL Tools"></topic></topic></topic><topic href="html/legal.html" label="Notices"></topic></toc>
\ No newline at end of file
+<toc topic="html/index.html" label="XSL Tools User Documentation"><topic href="html/introduction/gettingstarted.html" label="Getting Started"></topic><topic href="html/concepts/concepts.html" label="XSLT Concepts"><topic href="html/concepts/concepts.html#ResucingXSLT" label="Rescuing XSLT From Niche Status"><topic href="html/concepts/concepts.html#N10034" label="The Problem"></topic><topic href="html/concepts/concepts.html#N1005A" label="The Solution"></topic><topic href="html/concepts/concepts.html#N10081" label="Queries"><topic href="html/concepts/concepts.html#N1008F" label="xsl:for-each"></topic><topic href="html/concepts/concepts.html#N1009B" label="xsl:if"></topic><topic href="html/concepts/concepts.html#N100A5" label="xsl:choose"></topic></topic><topic href="html/concepts/concepts.html#N100AF" label="Conclusion"></topic></topic><topic href="html/concepts/resources.html" label="Resources"></topic></topic><topic href="html/editor/xsleditor.html" label="XSL Editing"><topic href="html/editor/xsleditor.html#Validation" label="Validation"></topic><topic href="html/editor/xsleditor_contentassist.html" label="Content Assist"><topic href="html/editor/xsleditor_contentassist.html#ed_XSLProposals" label="XSLT Element Proposals"></topic><topic href="html/editor/xsleditor_contentassist_selecttest.html" label="Select, Test, and Match Attributes"></topic><topic href="html/editor/xsleditor_contentassist_exclude.html" label="Exclude-Result-Prefixes"></topic><topic href="html/editor/xsleditor_contentassist_modeassist.html" label="Mode attribute assistance"></topic><topic href="html/editor/xsleditor_contentassist_namedtemplate.html" label="Named Template Assistance"></topic><topic href="html/editor/xsleditor_contentassist_calltemplate.html" label="Call-Template Assistance"></topic><topic href="html/editor/xsleditor_contentassist_include.html" label="Include and Import href Assistance"></topic></topic><topic href="html/editor/xsleditor_templates.html" label="Templates"><topic href="html/editor/xsleditor_templates.html#N101D3" label="XPath Templates"></topic></topic><topic href="html/editor/xsleditor_coloring.html" label="XSLT Syntax Coloring"></topic><topic href="html/editor/xsleditor_markers.html" label="XSLT Markers and Annotations"><topic href="html/editor/xsleditor_markers.html#xsltOverRide" label="Template Override"></topic></topic><topic href="html/editor/xsleditor_debugging.html" label="XSL Debugging"></topic><topic href="html/editor/xsleditor_debugging.html" label="Navigation"></topic></topic><topic href="html/launching/launching.html" label="XSL Launching and Debugging"><topic href="html/launching/launching.html#XSLLaunch" label="XSL Launching"></topic><topic href="html/launching/debugging.html" label="XSLT Debugging"><topic href="html/launching/debugging.html#DebugGettingStarted" label="Starting a Debug Session"></topic><topic href="html/launching/debugging_common.html" label="Common Debugging Operations"><topic href="html/launching/debugging_common.html#XSLDebugResultView" label="Result View"></topic><topic href="html/launching/debugging_variablesview.html" label="Variables View"></topic></topic><topic href="html/launching/debugging_processors.html" label="XSLT Processor Specific Support"><topic href="html/launching/debugging_processors.html#XSLDebugXalan" label="XSL Debugging with Xalan"></topic></topic></topic></topic><topic href="html/preferences/xslpreferences.html" label="XSL Tools Preferences"><topic href="html/preferences/xslpreferences.html#XSLFeatures" label="Features"></topic><topic href="html/preferences/xslprocessors.html" label="Installed Processors"></topic><topic href="html/preferences/xsloutputproperties.html" label="Output Properties"></topic><topic href="html/preferences/xpathtemplates.html" label="XPath Templates"><topic href="html/preferences/xpathtemplates.html#XPathTemplateNew" label="Creating New Templates"></topic><topic href="html/preferences/xpathimport.html" label="Import XPath Templates"></topic><topic href="html/preferences/xpathexport.html" label="Import XPath Templates"></topic></topic><topic href="html/preferences/validation.html" label="Project Validation Preferences"></topic><topic href="html/preferences/syntaxColoring.html" label="XSLT Syntax Coloring"></topic></topic><topic href="html/general/general.html" label="General"><topic href="html/general/general.html#XInclude" label="XInclude"></topic></topic><topic href="html/samples/samples.html" label="XSL Tooling Samples"><topic href="html/samples/samples.html#EclipseHelp" label="Eclipse Help"><topic href="html/samples/samples.html#DocbookEclipseHelp" label="Creating Eclipse Help with Docbook and XSL Tools"></topic><topic href="html/samples/samples.html#DITAEclipseHelp" label="Creating Eclipse Help with DITA and XSL Tools"></topic></topic></topic><topic href="html/legal.html" label="Notices"></topic></toc>
\ No newline at end of file