<commit_before>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2008-2010 The eXist Project
 *  http://exist-db.org
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  
 *  $Id$
 */
package org.exist.xslt;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.text.NumberFormat;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.apache.log4j.Logger;
import org.exist.EXistException;
import org.exist.dom.DocumentAtExist;
import org.exist.dom.ElementAtExist;
import org.exist.interpreter.ContextAtExist;
import org.exist.memtree.SAXAdapter;
import org.exist.storage.BrokerPool;
import org.exist.storage.DBBroker;
import org.exist.xquery.AnalyzeContextInfo;
import org.exist.xquery.Expression;
import org.exist.xquery.Optimizer;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.util.ExpressionDumper;
import org.exist.xslt.compiler.XSLElement;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

/**
 * <xsl:stylesheet version="1.0"
 *         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 * 
 * 	<xsl:import href="..."/>
 * 	<xsl:include href="..."/>
 * 	<xsl:strip-space elements="..."/>
 * 	<xsl:preserve-space elements="..."/>
 * 	<xsl:output method="..."/>
 * 	<xsl:key name="..." match="..." use="..."/>
 * 	<xsl:decimal-format name="..."/>
 * 	<xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/>
 * 	<xsl:attribute-set name="...">...</xsl:attribute-set>
 * 	<xsl:variable name="...">...</xsl:variable>
 * 	<xsl:param name="...">...</xsl:param>
 * 	<xsl:template match="...">...</xsl:template>
 * 	<xsl:template name="...">...</xsl:template>
 * </xsl:stylesheet>	
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class XSL {

    private final static Logger LOG = Logger.getLogger(XSL.class);

    public XSL() {
	}
    
    protected static XSLStylesheet compile(ElementAtExist source) throws XPathException {
    	BrokerPool pool = null;
    	DBBroker broker = null;
    	try {
        	pool = BrokerPool.getInstance();
    		broker = pool.get(null);
			return compile(source, broker);
		} catch (EXistException e) {
			throw new XPathException(e);
		} finally {
			if (pool != null) pool.release(broker);
		}
    }

    protected static XSLStylesheet compile(ElementAtExist source, DBBroker broker) throws XPathException {
    	long start = System.currentTimeMillis();
    	
    	XSLElement stylesheet = new XSLElement(source);
    	
    	ContextAtExist context = new XSLContext(broker);
    	
    	XSLStylesheet expr = (XSLStylesheet) stylesheet.compile(context);
    	AnalyzeContextInfo info = new AnalyzeContextInfo((XQueryContext)context);
    	info.setFlags(Expression.IN_NODE_CONSTRUCTOR);
        expr.analyze(info);

        if (context.optimizationsEnabled()) {
            Optimizer optimizer = new Optimizer((XQueryContext) context);
            expr.accept(optimizer);
            if (optimizer.hasOptimized()) {
                context.reset(true);
                expr.resetState(true);
                expr.analyze(new AnalyzeContextInfo());<commit_msg>[ignore] set default function namespace for xsl<commit_after>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2008-2010 The eXist Project
 *  http://exist-db.org
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  
 *  $Id$
 */
package org.exist.xslt;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.text.NumberFormat;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.apache.log4j.Logger;
import org.exist.EXistException;
import org.exist.dom.DocumentAtExist;
import org.exist.dom.ElementAtExist;
import org.exist.interpreter.ContextAtExist;
import org.exist.memtree.SAXAdapter;
import org.exist.storage.BrokerPool;
import org.exist.storage.DBBroker;
import org.exist.xquery.AnalyzeContextInfo;
import org.exist.xquery.Expression;
import org.exist.xquery.Optimizer;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.util.ExpressionDumper;
import org.exist.xslt.compiler.Factory;
import org.exist.xslt.compiler.XSLElement;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

/**
 * <xsl:stylesheet version="1.0"
 *         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 * 
 * 	<xsl:import href="..."/>
 * 	<xsl:include href="..."/>
 * 	<xsl:strip-space elements="..."/>
 * 	<xsl:preserve-space elements="..."/>
 * 	<xsl:output method="..."/>
 * 	<xsl:key name="..." match="..." use="..."/>
 * 	<xsl:decimal-format name="..."/>
 * 	<xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/>
 * 	<xsl:attribute-set name="...">...</xsl:attribute-set>
 * 	<xsl:variable name="...">...</xsl:variable>
 * 	<xsl:param name="...">...</xsl:param>
 * 	<xsl:template match="...">...</xsl:template>
 * 	<xsl:template name="...">...</xsl:template>
 * </xsl:stylesheet>	
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class XSL {

    private final static Logger LOG = Logger.getLogger(XSL.class);

    public XSL() {
	}
    
    protected static XSLStylesheet compile(ElementAtExist source) throws XPathException {
    	BrokerPool pool = null;
    	DBBroker broker = null;
    	try {
        	pool = BrokerPool.getInstance();
    		broker = pool.get(null);
			return compile(source, broker);
		} catch (EXistException e) {
			throw new XPathException(e);
		} finally {
			if (pool != null) pool.release(broker);
		}
    }

    protected static XSLStylesheet compile(ElementAtExist source, DBBroker broker) throws XPathException {
    	long start = System.currentTimeMillis();
    	
    	XSLElement stylesheet = new XSLElement(source);
    	
    	XSLContext context = new XSLContext(broker);
    	
    	context.setDefaultFunctionNamespace(Factory.namespaceURI);
    	
    	XSLStylesheet expr = (XSLStylesheet) stylesheet.compile(context);
    	AnalyzeContextInfo info = new AnalyzeContextInfo((XQueryContext)context);
    	info.setFlags(Expression.IN_NODE_CONSTRUCTOR);
        expr.analyze(info);

        if (context.optimizationsEnabled()) {
            Optimizer optimizer = new Optimizer((XQueryContext) context);
            expr.accept(optimizer);
            if (optimizer.hasOptimized()) {
                context.reset(true);
                expr.resetState(true);
                expr.analyze(new AnalyzeContextInfo());
{'fraction_non_alphanumeric': 0.1334493041749503, 'fraction_numerical': 0.00621272365805169, 'mean_word_length': 3.474152306837132, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6635958', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2520, 'n_words': 616}