[nobug] refactorings.
diff --git a/bundles/org.eclipse.wst.xsl.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.xsl.core/META-INF/MANIFEST.MF
index 687b3f4..aa7365a 100644
--- a/bundles/org.eclipse.wst.xsl.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.xsl.core/META-INF/MANIFEST.MF
@@ -23,6 +23,7 @@
  org.eclipse.wst.xsl.core.internal;x-friends:="org.eclipse.wst.xsl.*",
  org.eclipse.wst.xsl.core.internal.ant;x-internal:=true,
  org.eclipse.wst.xsl.core.internal.encoding;x-friends:="org.eclipse.wst.xsl.*",
+ org.eclipse.wst.xsl.core.internal.model;x-internal:=true,
  org.eclipse.wst.xsl.core.internal.modelhandler;x-friends:="org.eclipse.wst.xsl.*",
  org.eclipse.wst.xsl.core.internal.parser;x-friends:="org.eclipse.wst.xsl.*",
  org.eclipse.wst.xsl.core.internal.parser.regions;x-friends:="org.eclipse.wst.xsl.*",
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/XSLCore.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/XSLCore.java
index 1223927..dc5bc22 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/XSLCore.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/XSLCore.java
@@ -23,8 +23,7 @@
 import org.eclipse.wst.sse.core.StructuredModelManager;
 import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
 import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xsl.core.internal.StylesheetBuilder;
+import org.eclipse.wst.xsl.core.internal.model.StylesheetBuilder;
 import org.eclipse.wst.xsl.core.internal.util.FileUtil;
 import org.eclipse.wst.xsl.core.model.Stylesheet;
 import org.eclipse.wst.xsl.core.model.StylesheetModel;
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/StylesheetParser.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/StylesheetParser.java
deleted file mode 100644
index 0b86f7f..0000000
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/StylesheetParser.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Chase Technology Ltd - http://www.chasetechnology.co.uk
- * 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:
- *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
- *     David Carver (STAR) - bug 290286 - Model loading of parameters not respecting functions.
- *     David Carver (STAR) - no bug - Refactored Code for easier maintenance 
- *******************************************************************************/
-
-package org.eclipse.wst.xsl.core.internal;
-
-import java.util.Stack;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.*;
-import org.eclipse.wst.xsl.core.XSLCore;
-import org.eclipse.wst.xsl.core.model.*;
-import org.w3c.dom.*;
-
-public class StylesheetParser {
-	private final Stylesheet sf;
-	private final Stack<Element> elementStack = new Stack<Element>();
-	private Template currentTemplate;
-	private Stack<CallTemplate> callTemplates = new Stack<CallTemplate>();
-	private Stack<Function> functions = new Stack<Function>();
-	private XSLElement parentEl;
-
-	public StylesheetParser(Stylesheet stylesheet) {
-		this.sf = stylesheet;
-	}
-
-	public void walkDocument(IDOMDocument document) {
-
-		if (document.getDocumentElement() != null)
-			recurse(document.getDocumentElement());
-	}
-
-	private void recurse(Element element) {
-		XSLElement xslEl = null;
-		if (XSLCore.XSL_NAMESPACE_URI.equals(element.getNamespaceURI())) {
-			xslEl = createXSLModelObject(element, xslEl);
-		}
-		elementStack.push(element);
-		NodeList childNodes = element.getChildNodes();
-		for (int i = 0; i < childNodes.getLength(); i++) {
-			Node node = childNodes.item(i);
-			if (node.getNodeType() == Node.ELEMENT_NODE) {
-				recurse((Element) node);
-			}
-		}
-		
-		if (xslEl instanceof CallTemplate)
-			callTemplates.pop();
-		if (xslEl instanceof Function) {
-			functions.pop();
-		}
-		elementStack.pop();
-		// currentTemplate = null;
-		// currentCallTemplate = null;
-	}
-
-	private XSLElement createXSLModelObject(Element element, XSLElement xslEl) {
-		String elName = element.getLocalName();
-		int elementSize = elementStack.size();
-		if ("stylesheet".equals(elName) && elementSize == 0) //$NON-NLS-1$
-		{
-			xslEl = createStyleSheet(element);
-		} else if ("include".equals(elName) && elementSize == 1) //$NON-NLS-1$
-		{
-			xslEl = createInclude();
-		} else if ("import".equals(elName) && elementSize == 1) //$NON-NLS-1$
-		{
-			xslEl = createImport();
-		} else if ("template".equals(elName) && elementSize == 1) //$NON-NLS-1$
-		{
-			xslEl = createTemplate();
-		} else if ("param".equals(elName) && notParentStylesheet()) { //$NON-NLS-1$
-			xslEl = createParamater(element);
-		} else if ("call-template".equals(elName) && elementSize >= 2) //$NON-NLS-1$
-		{
-			xslEl = createCallTemplate();
-		} else if ("with-param".equals(elName) && elementSize >= 3 && callTemplates.size() > 0) //$NON-NLS-1$
-		{
-			xslEl = createWithParamParm(element);
-		} else if (isVariable(elName)) 
-		{
-			xslEl = createVariable(xslEl);
-		} else if ("function".equals(elName)) { //$NON-NLS-1$
-			xslEl = createFunction();
-		} else {
-			xslEl = new XSLElement(sf);
-		}
-		if (xslEl != null)
-			configure((IDOMNode) element, xslEl);
-		return xslEl;
-	}
-
-	private boolean isVariable(String elName) {
-		return "variable".equals(elName) || "param".equals(elName); //$NON-NLS-1$ //$NON-NLS-2$
-	}
-
-	private boolean notParentStylesheet() {
-		return parentEl.getModelType() != XSLModelObject.Type.STYLESHEET;
-	}
-
-	private XSLElement createFunction() {
-		currentTemplate = null;
-		Function function = new Function(sf);
-		functions.push(function);
-		sf.addFunction(function);
-		return function;
-	}
-
-	private XSLElement createVariable(XSLElement xslEl) {
-		if (elementStack.size() == 1) {// global variable
-			Variable var = new Variable(sf);
-			sf.addGlobalVariable(var);
-			xslEl = var;
-		} else if (elementStack.size() > 1 && currentTemplate != null) {// local
-																		// variable
-			Variable var = new Variable(sf);
-			currentTemplate.addVariable(var);
-			xslEl = var;
-		}
-		return xslEl;
-	}
-
-	private XSLElement createWithParamParm(Element element) {
-		Parameter param = new Parameter(sf);
-		// determine whether param has a value
-		NodeList childNodes = element.getChildNodes();
-		for (int i = 0; i < childNodes.getLength(); i++) {
-			Node childNode = childNodes.item(i);
-			if (childNode.getNodeType() != Node.ATTRIBUTE_NODE) {
-				param.setValue(true);
-				break;
-			}
-		}
-		// get the previous call-template
-		CallTemplate currentCallTemplate = callTemplates.peek();
-		currentCallTemplate.addParameter(param);
-		return param;
-	}
-
-	private XSLElement createCallTemplate() {
-		CallTemplate currentCallTemplate = new CallTemplate(sf);
-		callTemplates.push(currentCallTemplate);
-		sf.addCalledTemplate(currentCallTemplate);
-		return currentCallTemplate;
-	}
-
-	private XSLElement createParamater(Element element) {
-		Parameter param = new Parameter(sf);
-		// determine whether param has a value
-		NodeList childNodes = element.getChildNodes();
-		for (int i = 0; i < childNodes.getLength(); i++) {
-			Node childNode = childNodes.item(i);
-			if (childNode.getNodeType() != Node.ATTRIBUTE_NODE) {
-				param.setValue(true);
-				break;
-			}
-		}
-		if (parentEl.getModelType() == XSLModelObject.Type.FUNCTION) {
-			Function function = (Function) parentEl;
-			function.addParameter(param);
-		} else if (parentEl.getModelType() == XSLModelObject.Type.TEMPLATE
-				&& elementStack.size() == 2 && currentTemplate != null) {
-			Template template = (Template) parentEl;
-			template.addParameter(param);
-		}
-		return param;
-	}
-
-	private XSLElement createTemplate() {
-		currentTemplate = new Template(sf);
-		sf.addTemplate(currentTemplate);
-		return currentTemplate;
-	}
-
-	private XSLElement createImport() {
-		Import include = new Import(sf);
-		sf.addImport(include);
-		return include;
-	}
-
-	private XSLElement createInclude() {
-		Include include = new Include(sf);
-		sf.addInclude(include);
-		return include;
-	}
-
-	private XSLElement createStyleSheet(Element element) {
-		String version = element.getAttribute("version"); //$NON-NLS-1$
-		sf.setVersion(version);
-		return sf;
-	}
-
-	private void configure(IDOMNode node, XSLElement element) {
-		setPositionInfo(node, element);
-		IDOMElement domElem = (IDOMElement) node;
-		element.setName(domElem.getLocalName());
-		NamedNodeMap map = node.getAttributes();
-		for (int i = 0; i < map.getLength(); i++) {
-			IDOMAttr attr = (IDOMAttr) map.item(i);
-			XSLAttribute xslatt = new XSLAttribute(element, attr.getName(),
-					attr.getValue());
-			setPositionInfo(attr, xslatt);
-			element.setAttribute(xslatt);
-		}
-		setParentElement(node, element);
-	}
-
-	private void setParentElement(IDOMNode node, XSLElement element) {
-		if (parentEl != null)
-			parentEl.addChild(element);
-		if (node.hasChildNodes()) {
-			NodeList nodeList = node.getChildNodes();
-			for (int i = 0; i < nodeList.getLength(); i++) {
-				Node lnode = (Node) nodeList.item(i);
-				if (lnode.getNodeType() == Node.ELEMENT_NODE) {
-					parentEl = element; 
-					break;
-				}
-			}
-		}
-	}
-
-	private static void setPositionInfo(IDOMNode node, XSLNode inc) {
-		try {
-			IStructuredDocument structuredDocument = node
-					.getStructuredDocument();
-			int line = structuredDocument
-					.getLineOfOffset(node.getStartOffset());
-			int lineOffset = structuredDocument.getLineOffset(line);
-			int col = node.getStartOffset() - lineOffset;
-			inc.setOffset(node.getStartOffset());
-			inc.setLineNumber(line);
-			inc.setColumnNumber(col);
-			inc.setLength(node.getLength());
-		} catch (BadLocationException e) {
-			XSLCorePlugin.log(e);
-		}
-	}
-}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java
index 9334dab..7cfd502 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java
@@ -18,11 +18,7 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Plugin;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
-import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog;
 import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * The activator class controls the plug-in life cycle
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/StylesheetBuilder.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetBuilder.java
similarity index 79%
rename from bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/StylesheetBuilder.java
rename to bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetBuilder.java
index f06fab2..8c4788a 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/StylesheetBuilder.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetBuilder.java
@@ -11,42 +11,21 @@
  *     David Carver (STAR) - add XSL Functions element support and refactored
  *                           StyleSheet Parser
  *******************************************************************************/
-package org.eclipse.wst.xsl.core.internal;
+package org.eclipse.wst.xsl.core.internal.model;
 
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Stack;
-
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.wst.sse.core.StructuredModelManager;
 import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xsl.core.XSLCore;
+import org.eclipse.wst.xsl.core.internal.XSLCorePlugin;
 import org.eclipse.wst.xsl.core.internal.util.Debug;
-import org.eclipse.wst.xsl.core.model.CallTemplate;
-import org.eclipse.wst.xsl.core.model.Function;
-import org.eclipse.wst.xsl.core.model.Import;
-import org.eclipse.wst.xsl.core.model.Include;
-import org.eclipse.wst.xsl.core.model.Parameter;
 import org.eclipse.wst.xsl.core.model.Stylesheet;
-import org.eclipse.wst.xsl.core.model.Template;
-import org.eclipse.wst.xsl.core.model.Variable;
-import org.eclipse.wst.xsl.core.model.XSLAttribute;
-import org.eclipse.wst.xsl.core.model.XSLElement;
-import org.eclipse.wst.xsl.core.model.XSLNode;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 /**
  * A builder that creates and maintains a cache of <code>Stylesheet</code>'s.
@@ -152,9 +131,9 @@
 		if (builtFiles.isEmpty()) {
 			return;
 		}
-		Iterator it = builtFiles.keySet().iterator();
+		Iterator<IFile> it = builtFiles.keySet().iterator();
 		while (it.hasNext()) {
-			IFile key = (IFile) it.next();
+			it.next();
 			it.remove();
 		}
 	}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetParser.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetParser.java
new file mode 100644
index 0000000..68a8639
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetParser.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 Chase Technology Ltd - http://www.chasetechnology.co.uk
+ * 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:
+ *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
+ *     David Carver (STAR) - bug 290286 - Model loading of parameters not respecting functions.
+ *     David Carver (STAR) - no bug - Refactored Code for easier maintenance 
+ *******************************************************************************/
+
+package org.eclipse.wst.xsl.core.internal.model;
+
+import java.util.Stack;
+
+import org.eclipse.wst.xml.core.internal.provisional.document.*;
+import org.eclipse.wst.xsl.core.XSLCore;
+import org.eclipse.wst.xsl.core.model.*;
+import org.w3c.dom.*;
+
+public class StylesheetParser {
+	private StylesheetParserData stylesheetParserData = new StylesheetParserData(
+			new Stack<Element>(), new Stack<CallTemplate>(), new Stack<Function>());
+
+	public StylesheetParser(Stylesheet stylesheet) {
+		this.stylesheetParserData.setStylesheet(stylesheet);
+	}
+
+	public void walkDocument(IDOMDocument document) {
+
+		if (document.getDocumentElement() != null)
+			recurse(document.getDocumentElement());
+	}
+
+	private void recurse(Element element) {
+		XSLElement xslEl = null;
+		if (XSLCore.XSL_NAMESPACE_URI.equals(element.getNamespaceURI())) {
+			XSLModelObjectFactory factory = new XSLModelObjectFactory(element, xslEl, stylesheetParserData);
+			xslEl = factory.createXSLModelObject();
+		}
+		stylesheetParserData.getElementStack().push(element);
+		NodeList childNodes = element.getChildNodes();
+		for (int i = 0; i < childNodes.getLength(); i++) {
+			Node node = childNodes.item(i);
+			if (node.getNodeType() == Node.ELEMENT_NODE) {
+				recurse((Element) node);
+			}
+		}
+		
+		if (xslEl instanceof CallTemplate)
+			stylesheetParserData.getCallTemplates().pop();
+		if (xslEl instanceof Function) {
+			stylesheetParserData.getFunctions().pop();
+		}
+		stylesheetParserData.getElementStack().pop();
+	}
+}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetParserData.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetParserData.java
new file mode 100644
index 0000000..5e5a3dc
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/StylesheetParserData.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.core.internal.model;
+
+import java.util.Stack;
+
+import org.eclipse.wst.xsl.core.model.CallTemplate;
+import org.eclipse.wst.xsl.core.model.Function;
+import org.eclipse.wst.xsl.core.model.Stylesheet;
+import org.eclipse.wst.xsl.core.model.Template;
+import org.eclipse.wst.xsl.core.model.XSLElement;
+import org.w3c.dom.Element;
+
+/**
+ * This class is used to hold Data necessary for parsing and walking
+ * an XSL Stylesheet into a Model.
+ * 
+ * @author dcarver
+ * @since 1.1
+ */
+public class StylesheetParserData {
+	private Stylesheet stylesheet;
+	private Stack<Element> elementStack;
+
+	private Template currentTemplate;
+
+	private Stack<CallTemplate> callTemplates;
+
+	private Stack<Function> functions;
+
+	private XSLElement parentEl;
+
+	public StylesheetParserData(Stack<Element> elementStack,
+			Stack<CallTemplate> callTemplates, Stack<Function> functions) {
+		this.elementStack = elementStack;
+		this.callTemplates = callTemplates;
+		this.functions = functions;
+	}
+
+	public Stack<CallTemplate> getCallTemplates() {
+		return callTemplates;
+	}
+
+	public Template getCurrentTemplate() {
+		return currentTemplate;
+	}
+
+	public Stack<Element> getElementStack() {
+		return elementStack;
+	}
+
+	public Stack<Function> getFunctions() {
+		return functions;
+	}
+
+	public XSLElement getParentEl() {
+		return parentEl;
+	}
+
+	public Stylesheet getStylesheet() {
+		return stylesheet;
+	}
+
+	public void setCallTemplates(Stack<CallTemplate> callTemplates) {
+		this.callTemplates = callTemplates;
+	}
+	public void setCurrentTemplate(Template currentTemplate) {
+		this.currentTemplate = currentTemplate;
+	}
+	public void setElementStack(Stack<Element> elementStack) {
+		this.elementStack = elementStack;
+	}
+	public void setFunctions(Stack<Function> functions) {
+		this.functions = functions;
+	}
+	public void setParentEl(XSLElement parentEl) {
+		this.parentEl = parentEl;
+	}
+
+	public void setStylesheet(Stylesheet sf) {
+		this.stylesheet = sf;
+	}
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/XSLElementFactory.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/XSLElementFactory.java
new file mode 100644
index 0000000..3057f0c
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/XSLElementFactory.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.core.internal.model;
+
+import org.eclipse.wst.xsl.core.model.CallTemplate;
+import org.eclipse.wst.xsl.core.model.Function;
+import org.eclipse.wst.xsl.core.model.Import;
+import org.eclipse.wst.xsl.core.model.Include;
+import org.eclipse.wst.xsl.core.model.Parameter;
+import org.eclipse.wst.xsl.core.model.Template;
+import org.eclipse.wst.xsl.core.model.Variable;
+import org.eclipse.wst.xsl.core.model.XSLElement;
+import org.eclipse.wst.xsl.core.model.XSLModelObject;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A Factory that creates XSL Elements of the requested type.
+ * @since 1.1
+ */
+public class XSLElementFactory {
+
+	private StylesheetParserData stylesheetParserData;
+	private Element element;
+	
+	public XSLElementFactory(StylesheetParserData data, Element element) {
+		stylesheetParserData = data;
+		this.element = element;
+	}
+		
+	public XSLElement createStyleSheet() {
+		String version = element.getAttribute("version"); //$NON-NLS-1$
+		stylesheetParserData.getStylesheet().setVersion(version);
+		return stylesheetParserData.getStylesheet();
+	}
+	
+	public XSLElement createInclude() {
+		Include include = new Include(stylesheetParserData.getStylesheet());
+		stylesheetParserData.getStylesheet().addInclude(include);
+		return include;
+	}
+	
+	public XSLElement createImport() {
+		Import include = new Import(stylesheetParserData.getStylesheet());
+		stylesheetParserData.getStylesheet().addImport(include);
+		return include;
+	}
+	
+	public XSLElement createTemplate() {
+		stylesheetParserData.setCurrentTemplate(new Template(stylesheetParserData.getStylesheet()));
+		stylesheetParserData.getStylesheet().addTemplate(stylesheetParserData.getCurrentTemplate());
+		return stylesheetParserData.getCurrentTemplate();
+	}
+	
+	public XSLElement createParamater() {
+		Parameter param = new Parameter(stylesheetParserData.getStylesheet());
+		// determine whether param has a value
+		NodeList childNodes = element.getChildNodes();
+		for (int i = 0; i < childNodes.getLength(); i++) {
+			Node childNode = childNodes.item(i);
+			if (childNode.getNodeType() != Node.ATTRIBUTE_NODE) {
+				param.setValue(true);
+				break;
+			}
+		}
+		if (stylesheetParserData.getParentEl().getModelType() == XSLModelObject.Type.FUNCTION) {
+			Function function = (Function) stylesheetParserData.getParentEl();
+			function.addParameter(param);
+		} else if (stylesheetParserData.getParentEl().getModelType() == XSLModelObject.Type.TEMPLATE
+				&& stylesheetParserData.getElementStack().size() == 2 && stylesheetParserData.getCurrentTemplate() != null) {
+			Template template = (Template) stylesheetParserData.getParentEl();
+			template.addParameter(param);
+		}
+		return param;
+	}
+	
+	public XSLElement createCallTemplate() {
+		CallTemplate currentCallTemplate = new CallTemplate(stylesheetParserData.getStylesheet());
+		stylesheetParserData.getCallTemplates().push(currentCallTemplate);
+		stylesheetParserData.getStylesheet().addCalledTemplate(currentCallTemplate);
+		return currentCallTemplate;
+	}
+
+	public XSLElement createWithParamParm() {
+		Parameter param = new Parameter(stylesheetParserData.getStylesheet());
+		// determine whether param has a value
+		NodeList childNodes = element.getChildNodes();
+		for (int i = 0; i < childNodes.getLength(); i++) {
+			Node childNode = childNodes.item(i);
+			if (childNode.getNodeType() != Node.ATTRIBUTE_NODE) {
+				param.setValue(true);
+				break;
+			}
+		}
+		// get the previous call-template
+		CallTemplate currentCallTemplate = stylesheetParserData.getCallTemplates().peek();
+		currentCallTemplate.addParameter(param);
+		return param;
+	}
+
+	public XSLElement createVariable(XSLElement xslEl) {
+		if (stylesheetParserData.getElementStack().size() == 1) {// global variable
+			Variable var = new Variable(stylesheetParserData.getStylesheet());
+			stylesheetParserData.getStylesheet().addGlobalVariable(var);
+			xslEl = var;
+		} else if (stylesheetParserData.getElementStack().size() > 1 && stylesheetParserData.getCurrentTemplate() != null) {// local
+																		// variable
+			Variable var = new Variable(stylesheetParserData.getStylesheet());
+			stylesheetParserData.getCurrentTemplate().addVariable(var);
+			xslEl = var;
+		}
+		return xslEl;
+	}
+	
+	public XSLElement createFunction() {
+		stylesheetParserData.setCurrentTemplate(null);
+		Function function = new Function(stylesheetParserData.getStylesheet());
+		stylesheetParserData.getFunctions().push(function);
+		stylesheetParserData.getStylesheet().addFunction(function);
+		return function;
+	}
+	
+	public XSLElement createXSLElement() {
+		return new XSLElement(stylesheetParserData.getStylesheet());
+	}
+	
+	
+}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/XSLModelObjectFactory.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/XSLModelObjectFactory.java
new file mode 100644
index 0000000..5b150a8
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/model/XSLModelObjectFactory.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.core.internal.model;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xsl.core.internal.XSLCorePlugin;
+import org.eclipse.wst.xsl.core.model.XSLAttribute;
+import org.eclipse.wst.xsl.core.model.XSLElement;
+import org.eclipse.wst.xsl.core.model.XSLModelObject;
+import org.eclipse.wst.xsl.core.model.XSLNode;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class XSLModelObjectFactory {
+	private static final String VARIABLE = "variable"; //$NON-NLS-1$
+	private static final String FUNCTION = "function"; //$NON-NLS-1$
+	private static final String WITH_PARAM = "with-param"; //$NON-NLS-1$
+	private static final String CALL_TEMPLATE = "call-template"; //$NON-NLS-1$
+	private static final String PARAM = "param"; //$NON-NLS-1$
+	private static final String TEMPLATE = "template"; //$NON-NLS-1$
+	private static final String IMPORT = "import"; //$NON-NLS-1$
+	private static final String INCLUDE = "include"; //$NON-NLS-1$
+	private static final String STYLESHEET = "stylesheet"; //$NON-NLS-1$
+	
+	private Element element;
+	private XSLElement xslEl;
+	private StylesheetParserData stylesheetParserData;
+
+	public XSLModelObjectFactory(Element element, XSLElement xslEl,
+			StylesheetParserData data) {
+		this.element = element;
+		this.xslEl = xslEl;
+		stylesheetParserData = data;
+	}
+
+	/**
+	 * Creates an XSL Model Object of the appropriate type.
+	 * @return
+	 */
+	public XSLElement createXSLModelObject() {
+		String elName = element.getLocalName();
+		int elementSize = stylesheetParserData.getElementStack().size();
+		XSLElementFactory factory = new XSLElementFactory(stylesheetParserData,
+				element);
+		if (elementSize == 0) {
+			if (STYLESHEET.equals(elName)) {
+				xslEl = factory.createStyleSheet();
+			}
+		}else if (INCLUDE.equals(elName) && elementSize == 1)
+		{
+			xslEl = factory.createInclude();
+		} else if (IMPORT.equals(elName) && elementSize == 1)
+		{
+			xslEl = factory.createImport();
+		} else if (TEMPLATE.equals(elName) && elementSize == 1)
+		{
+			xslEl = factory.createTemplate();
+		} else if (PARAM.equals(elName) && notParentStylesheet()) {
+			xslEl = factory.createParamater();
+		} else if (CALL_TEMPLATE.equals(elName) && elementSize >= 2) 
+		{
+			xslEl = factory.createCallTemplate();
+		} else if (WITH_PARAM.equals(elName) && elementSize >= 3
+				&& stylesheetParserData.getCallTemplates().size() > 0) 
+		{
+			xslEl = factory.createWithParamParm();
+		} else if (isVariable(elName)) {
+			xslEl = factory.createVariable(xslEl);
+		} else if (FUNCTION.equals(elName)) { 
+			xslEl = factory.createFunction();
+		} else {
+			xslEl = factory.createXSLElement();
+		}
+		if (xslEl != null)
+			configure((IDOMNode) element, xslEl);
+		return xslEl;
+	}
+
+	private boolean isVariable(String elName) {
+		return VARIABLE.equals(elName) || PARAM.equals(elName);
+	}
+
+	private boolean notParentStylesheet() {
+		return stylesheetParserData.getParentEl().getModelType() != XSLModelObject.Type.STYLESHEET;
+	}
+
+	private void configure(IDOMNode node, XSLElement element) {
+		setPositionInfo(node, element);
+		IDOMElement domElem = (IDOMElement) node;
+		element.setName(domElem.getLocalName());
+		NamedNodeMap map = node.getAttributes();
+		for (int i = 0; i < map.getLength(); i++) {
+			IDOMAttr attr = (IDOMAttr) map.item(i);
+			XSLAttribute xslatt = new XSLAttribute(element, attr.getName(),
+					attr.getValue());
+			setPositionInfo(attr, xslatt);
+			element.setAttribute(xslatt);
+		}
+		setParentElement(node, element);
+	}
+
+	private void setParentElement(IDOMNode node, XSLElement element) {
+		if (stylesheetParserData.getParentEl() != null)
+			stylesheetParserData.getParentEl().addChild(element);
+		if (node.hasChildNodes()) {
+			NodeList nodeList = node.getChildNodes();
+			for (int i = 0; i < nodeList.getLength(); i++) {
+				Node lnode = nodeList.item(i);
+				if (lnode.getNodeType() == Node.ELEMENT_NODE) {
+					stylesheetParserData.setParentEl(element);
+					break;
+				}
+			}
+		}
+	}
+
+	private static void setPositionInfo(IDOMNode node, XSLNode inc) {
+		try {
+			IStructuredDocument structuredDocument = node
+					.getStructuredDocument();
+			int line = structuredDocument
+					.getLineOfOffset(node.getStartOffset());
+			int lineOffset = structuredDocument.getLineOffset(line);
+			int col = node.getStartOffset() - lineOffset;
+			inc.setOffset(node.getStartOffset());
+			inc.setLineNumber(line);
+			inc.setColumnNumber(col);
+			inc.setLength(node.getLength());
+		} catch (BadLocationException e) {
+			XSLCorePlugin.log(e);
+		}
+	}
+
+}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java
index c9cd010..d2262c1 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java
@@ -134,7 +134,7 @@
 		// template checks
 		checkTemplates(stylesheetComposed, report);
 		
-		if (stylesheetComposed.getStylesheet().getVersion().equals("2.0")) {
+		if (stylesheetComposed.getStylesheet().getVersion().equals("2.0")) { //$NON-NLS-1$
 			checkFunctions(stylesheetComposed, report);
 		}
 		// call-template checks
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Parameter.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Parameter.java
index 8ca52c9..996835e 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Parameter.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Parameter.java
@@ -63,6 +63,7 @@
 	/**
 	 * @since 1.1
 	 */
+	@Override
 	public String getAs() {
 		return getAttributeValue("as"); //$NON-NLS-1$
 	}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Stylesheet.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Stylesheet.java
index 169a3b8..e536acb 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Stylesheet.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/Stylesheet.java
@@ -185,6 +185,7 @@
 	}
 	
 	/**
+	 * @param function 
 	 * @since 1.1
 	 */
 	public void addFunction(Function function) {
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/StylesheetModel.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/StylesheetModel.java
index d6b46fe..339301e 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/StylesheetModel.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/model/StylesheetModel.java
@@ -14,7 +14,6 @@
 
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -270,6 +269,8 @@
 	}
 
 	/**
+	 * Get a List of all functions that are known.
+	 * @return 
 	 * @since 1.1
 	 */
 	public List<Function> getFunctions() {