Java tutorial
//package com.java2s; /** * 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 3 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, see <http://www.gnu.org/licenses/>. */ public class Main { public static String createXSLT(String xpathExpression, String transformation) { StringBuilder stylesheet = new StringBuilder(); stylesheet.append("<?xml version='1.0'?>\n"); stylesheet.append("<xsl:stylesheet version=\"1.0\"\n"); stylesheet.append("\txmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >\n"); stylesheet.append("\t<xsl:output omit-xml-declaration=\"no\" indent=\"yes\"/>\n\n"); stylesheet.append("\t<xsl:template match=\"@* | node()\">\n"); stylesheet.append("\t\t<xsl:copy>\n"); stylesheet.append("\t\t\t<xsl:apply-templates select=\"@* | node()\" />\n"); stylesheet.append("\t\t</xsl:copy>\n"); stylesheet.append("\t</xsl:template>\n"); stylesheet.append("\t<xsl:template match=\"").append(xpathExpression).append("\">\n"); stylesheet.append(transformation); stylesheet.append("\t</xsl:template>\n"); stylesheet.append("</xsl:stylesheet>\n"); return stylesheet.toString(); } }