package gov.nih.nci.cbiit.cmts.transform.artifact;

import java.io.IOException;
import java.io.Writer;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;



public class XSLTStylesheet extends Document  {
	private String xsltPrefix="xsl";
	private String xsltUri="http://www.w3.org/1999/XSL/Transform";
	protected static Namespace xsltNamespace=Namespace.getNamespace("xsl","http://www.w3.org/1999/XSL/Transform");
	public XSLTStylesheet()
	{
		super();
		XSLTElement xlstRoot = new XSLTElement("transform");
		xlstRoot.setAttribute("version", "1.0");
		setRootElement(xlstRoot);
		XSLTElement outputElement=new XSLTElement("output");
		outputElement.setAttribute("method","xml");
		xlstRoot.addContent(outputElement);
	}

	/**
	 * <xsl:template> is top level element, add it to the root element 
	 * @param template
	 */
	public void addTempate(Element template)
	{
		getRootElement().addContent(template);
	}
	public void writeOut(Writer out) throws IOException
	{
		Format outFormat=Format.getPrettyFormat();
		outFormat.setLineSeparator("\n");
		XMLOutputter xmlOut=new XMLOutputter(outFormat);
//		xmlOut.getFormat().setEncoding("ISO-8859-1");
//		xmlOut.getFormat().setLineSeparator("\n");
		xmlOut.output(this, out);
	}
}

@@ -315,64 +315,76 @@
 %0A%09pr
-ivate String xsltPrefix=%22xsl%22;%0D%0A%09private String xsltUri=
+otected static Namespace xsltNamespace=Namespace.getNamespace(%22xsl%22,
 %22htt
@@ -421,21 +421,20 @@
 orm%22
+)
 ;%0D%0A%09pr
-otected
+ivate
  sta
@@ -441,34 +441,32 @@
 tic Namespace xs
-lt
 Namespace=Namesp
@@ -477,33 +477,32 @@
 getNamespace(%22xs
-l
 %22,%22http://www.w3
@@ -506,34 +506,30 @@
 .w3.org/
-1999/XSL/Transform
+2001/XMLSchema
 %22);%0D%0A%09pu
@@ -619,24 +619,74 @@
 ansform%22);%0D%0A
+%09%09xlstRoot.addNamespaceDeclaration(xsNamespace);%0D%0A
 %09%09xlstRoot.s

add XMLSchema namespace with prefix "xs" to use schema datatype xs:date()