private void collapseAttributes(Node oldNode, Element newNode) throws XPathExpressionException
	{
		NodeList attrElements = XpathUtils.executeQuery(oldNode, "xsl:attribute[count(text()|./xsl:text|./xsl:value-of)=count(node())]");
		for(int i=0; i<attrElements.getLength(); i++)//for each xsl:attribute element
		{
			Node next = oldNode.removeChild(attrElements.item(i));
			NodeList nextKids = next.getChildNodes();
			String attributeName = NamedNode.getNodeName(next);
			StringBuilder attributeValue = new StringBuilder();
			for(int j=0; j < nextKids.getLength(); j++)//for each child of the xsl:attribute element
    		{
				Node kid = nextKids.item(j);
				if(kid.getNodeType() == Node.TEXT_NODE)
				{
					String nextVal = kid.getNodeValue().trim();
					if(nextVal.length() > 0)
					{
						attributeValue.append(nextVal);
	}
}
				else if(kid.getNodeName().equals("xsl:text"))
				{
					attributeValue.append(kid.getTextContent());
				}
				else if(kid.getNodeName().equals("xsl:value-of"))
				{
					String valSelect = kid.getAttributes().getNamedItem("select").getNodeValue();
					/*
					 * useful regexps:
					 * "^(['|\"])(.+)\\1$" string literal
					 * "^\\{?\\$[^}]+\\}?$" variable reference (with or without curly braces)
					 * "^\\d+$" numeric
					 * "^(?:[a-z]+:)?[a-z-]+\\([^)]+\\)$" xpath function
					 */
					if(valSelect.matches("^(['|\"])(.+)\\1$"))
					{
						attributeValue.append(valSelect.replaceAll("^['|\"]|['|\"]$", ""));
					}
					else
					{
						attributeValue.append("{");
						attributeValue.append(valSelect);
						attributeValue.append("}");
					}
				}
				else
				{
					System.out.println("What the...? " + kid.getNodeName());
				}
    		}
			if(attributeValue.length() > 0)
			{
				newNode.setAttribute(attributeName, attributeValue.toString());
			}
		}
	}