0001: /* Copyright 2002-2005 Elliotte Rusty Harold
0002:
0003: This library is free software; you can redistribute it and/or modify
0004: it under the terms of version 2.1 of the GNU Lesser General Public
0005: License as published by the Free Software Foundation.
0006:
0007: This library is distributed in the hope that it will be useful,
0008: but WITHOUT ANY WARRANTY; without even the implied warranty of
0009: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0010: GNU Lesser General Public License for more details.
0011:
0012: You should have received a copy of the GNU Lesser General Public
0013: License along with this library; if not, write to the
0014: Free Software Foundation, Inc., 59 Temple Place, Suite 330,
0015: Boston, MA 02111-1307 USA
0016:
0017: You can contact Elliotte Rusty Harold by sending e-mail to
0018: elharo@metalab.unc.edu. Please include the word "XOM" in the
0019: subject line. The XOM home page is located at http://www.xom.nu/
0020: */
0021: package nu.xom.tests;
0022:
0023: import java.io.ByteArrayOutputStream;
0024: import java.io.File;
0025: import java.io.FileNotFoundException;
0026: import java.io.FileOutputStream;
0027: import java.io.IOException;
0028: import java.io.OutputStream;
0029: import java.io.PrintStream;
0030: import java.net.UnknownHostException;
0031: import java.util.MissingResourceException;
0032:
0033: import nu.xom.Attribute;
0034: import nu.xom.Builder;
0035: import nu.xom.Comment;
0036: import nu.xom.DocType;
0037: import nu.xom.Document;
0038: import nu.xom.Element;
0039: import nu.xom.Elements;
0040: import nu.xom.IllegalAddException;
0041: import nu.xom.MalformedURIException;
0042: import nu.xom.Namespace;
0043: import nu.xom.Node;
0044: import nu.xom.NodeFactory;
0045: import nu.xom.Nodes;
0046: import nu.xom.ParentNode;
0047: import nu.xom.ParsingException;
0048: import nu.xom.ProcessingInstruction;
0049: import nu.xom.Serializer;
0050: import nu.xom.Text;
0051: import nu.xom.XMLException;
0052: import nu.xom.xslt.XSLException;
0053: import nu.xom.xslt.XSLTransform;
0054:
0055: /**
0056: * <p>
0057: * Unit tests for the XSLT engine.
0058: * </p>
0059: *
0060: * <p>
0061: * Many of the tests in this suite use an identity transformation.
0062: * This is often done to make sure I get a particular content into
0063: * the output tree in order to test the XSLTHandler.
0064: * </p>
0065: *
0066: * @author Elliotte Rusty Harold
0067: * @version 1.1b6
0068: *
0069: */
0070: public class XSLTransformTest extends XOMTestCase {
0071:
0072: public XSLTransformTest(String name) {
0073: super (name);
0074: }
0075:
0076: // Not a literal result element as stylesheet
0077: // because it's missing the xsl:version attribute
0078: private String notAStyleSheet = "<?xml-stylesheet href=\"file.css\" type=\"text/css\"?>"
0079: + "<!-- test -->"
0080: + "<test xmlns:xlink='http://www.w3.org/TR/1999/xlink'>Hello dear"
0081: + "\r\n<em id=\"p1\" xmlns:none=\"http://www.example.com\">"
0082: + "very important</em>"
0083: + "<span xlink:type='simple'>here's the link</span>\r\n"
0084: + "<svg:svg xmlns:svg='http://www.w3.org/TR/2000/svg'>"
0085: + "<svg:text>text in a namespace</svg:text></svg:svg>\r\n"
0086: + "<svg xmlns='http://www.w3.org/TR/2000/svg'>"
0087: + "<text>text in a namespace</text></svg>"
0088: + "</test>\r\n"
0089: + "<!--epilog-->";
0090:
0091: // This class tests a lot of error conditions, which
0092: // Xalan annoyingly logs to System.err. This hides System.err
0093: // before each test and restores it after each test.
0094: private PrintStream systemErr = System.err;
0095:
0096: private File inputDir;
0097:
0098: protected void setUp() {
0099:
0100: System.setErr(new PrintStream(new ByteArrayOutputStream()));
0101:
0102: inputDir = new File("data");
0103: inputDir = new File(inputDir, "xslt");
0104: inputDir = new File(inputDir, "input");
0105:
0106: }
0107:
0108: protected void tearDown() {
0109: System.setErr(systemErr);
0110: }
0111:
0112: // Primarily this makes sure the XSLTHandler can handle various
0113: // edge cases
0114: public void testIdentityTransform() throws ParsingException,
0115: IOException, XSLException {
0116:
0117: File stylesheet = new File(inputDir, "identity.xsl");
0118: Builder builder = new Builder();
0119: Document stylesheetDoc = builder.build(stylesheet);
0120: XSLTransform xform = new XSLTransform(stylesheetDoc);
0121: Element root = new Element("root", "http://www.example.org");
0122: root.appendChild(new Text("some data"));
0123: root.appendChild(new Element("something"));
0124: root.addAttribute(new Attribute("test", "test"));
0125: root.addAttribute(new Attribute("pre:red",
0126: "http://www.red.com/", "value"));
0127: Document input = new Document(root);
0128: Nodes output = xform.transform(input);
0129: assertEquals(root, output.get(0));
0130:
0131: }
0132:
0133: public void testPrefixMappingIssues() throws XSLException,
0134: ParsingException, IOException {
0135:
0136: String doc = "<test>"
0137: + "<span xmlns:a='http://www.example.com'/>"
0138: + "<span xmlns:b='http://www.example.net'/>"
0139: + "</test>";
0140: File stylesheet = new File(inputDir, "identity.xsl");
0141: Builder builder = new Builder();
0142: Document stylesheetDoc = builder.build(stylesheet);
0143: XSLTransform xform = new XSLTransform(stylesheetDoc);
0144: Document input = builder.build(doc, "http://example.org/");
0145: Nodes result = xform.transform(input);
0146: assertEquals(input.getRootElement(), result.get(0));
0147:
0148: }
0149:
0150: public void testDocumentConstructor() throws ParsingException,
0151: IOException {
0152:
0153: try {
0154: Builder builder = new Builder();
0155: Document doc = builder.build(notAStyleSheet,
0156: "http://www.example.com");
0157: new XSLTransform(doc);
0158: /*Document input = builder.build("<root />", "http://example.org/");
0159: Nodes result = xform.transform(input); */
0160: fail("Compiled non-stylesheet");
0161: } catch (XSLException success) {
0162: assertNotNull(success.getMessage());
0163: }
0164:
0165: }
0166:
0167: public void testLiteralResultElementUsedAsStylesheet()
0168: throws ParsingException, IOException, XSLException {
0169:
0170: String literalResultElementAsStylesheet = "<html xsl:version='1.0'\n"
0171: + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\n"
0172: + " xmlns='http://www.w3.org/TR/xhtml1/strict'>\n"
0173: + " <head>\n"
0174: + " <title>Expense Report Summary</title>\n"
0175: + " </head>\n"
0176: + " <body>\n"
0177: + " <p>Total Amount: <xsl:value-of select='expense-report/total'/></p>\n"
0178: + " </body>\n" + "</html>\n";
0179:
0180: Builder builder = new Builder();
0181: Document stylesheet = builder.build(
0182: literalResultElementAsStylesheet,
0183: "http://www.example.com");
0184: XSLTransform transform = new XSLTransform(stylesheet);
0185: Document doc = builder.build(notAStyleSheet,
0186: "http://www.example.com");
0187: Nodes result = transform.transform(doc);
0188: Element root = (Element) (result.get(0));
0189: assertEquals("html", root.getQualifiedName());
0190: assertEquals(2, root.getChildCount());
0191:
0192: }
0193:
0194: /* <xsl:template match="/">
0195: <element1>some data and <content/> for a test</element1>
0196: <element2>Remember, the XSLT processor is going to strip out the literal white space</element2>
0197: <element3>some data and <content/> for a <!--test--></element3>
0198: <element4/>
0199: <xsl:comment>test</xsl:comment>
0200: <xsl:processing-instruction name="test">PIs are not treated as literals in XSLT?</xsl:processing-instruction>
0201: </xsl:template> */
0202:
0203: public void testCreateDocumentFragment() throws ParsingException,
0204: IOException, XSLException {
0205:
0206: Element element1 = new Element("element1");
0207: element1.appendChild("some data and ");
0208: element1.appendChild(new Element("content"));
0209: element1.appendChild(" for a test");
0210:
0211: Element element2 = new Element("element2");
0212: element2
0213: .appendChild("Remember, the XSLT processor is going to strip out the literal white space");
0214: File doc = new File(inputDir, "8-14.xml");
0215: File stylesheet = new File(inputDir, "fragment.xsl");
0216: Builder builder = new Builder();
0217: Document stylesheetDoc = builder.build(stylesheet);
0218: XSLTransform xform = new XSLTransform(stylesheetDoc);
0219: Document input = builder.build(doc);
0220: Nodes output = xform.transform(input);
0221: assertEquals(6, output.size());
0222: assertEquals(element1, output.get(0));
0223: assertEquals(element2, output.get(1));
0224: assertEquals(new Element("element4"), output.get(3));
0225: assertEquals(new Comment("test"), output.get(4));
0226: assertEquals(new ProcessingInstruction("test",
0227: "PIs are not treated as literals in XSLT?"), output
0228: .get(5));
0229:
0230: }
0231:
0232: public void testTransform() throws ParsingException, IOException,
0233: XSLException {
0234:
0235: File doc = new File(inputDir, "8-1.xml");
0236: File stylesheet = new File(inputDir, "8-8.xsl");
0237: Builder builder = new Builder();
0238: Document stylesheetDoc = builder.build(stylesheet);
0239: XSLTransform xform = new XSLTransform(stylesheetDoc);
0240: Nodes output = xform.transform(builder.build(doc));
0241: assertEquals(1, output.size());
0242: Document result = new Document((Element) (output.get(0)));
0243:
0244: Document expected = builder.build("data/xslt/output/8-8.xml");
0245: assertEquals(expected, result);
0246:
0247: }
0248:
0249: public void testSetParameter() throws ParsingException,
0250: IOException, XSLException {
0251:
0252: File doc = new File(inputDir, "8-1.xml");
0253: File stylesheet = new File(inputDir, "paramtest.xsl");
0254: Builder builder = new Builder();
0255: Document stylesheetDoc = builder.build(stylesheet);
0256: XSLTransform xform = new XSLTransform(stylesheetDoc);
0257: xform.setParameter("test", new Double(2));
0258: Nodes output = xform.transform(builder.build(doc));
0259: assertEquals(1, output.size());
0260: Element result = (Element) output.get(0);
0261: assertEquals("<root>2</root>", result.toXML());
0262:
0263: }
0264:
0265: public void testSetParameterWithNamespace()
0266: throws ParsingException, IOException, XSLException {
0267:
0268: File doc = new File(inputDir, "8-1.xml");
0269: File stylesheet = new File(inputDir, "namespaceparamtest.xsl");
0270: Builder builder = new Builder();
0271: Document stylesheetDoc = builder.build(stylesheet);
0272: XSLTransform xform = new XSLTransform(stylesheetDoc);
0273: xform.setParameter("test", "http://www.xom.nu/", new Double(2));
0274: Nodes output = xform.transform(builder.build(doc));
0275: assertEquals(1, output.size());
0276: Element result = (Element) output.get(0);
0277: assertEquals("<root xmlns:pre=\"http://www.xom.nu/\">2</root>",
0278: result.toXML());
0279:
0280: }
0281:
0282: public void testRemoveParameterWithNamespace()
0283: throws ParsingException, IOException, XSLException {
0284:
0285: File doc = new File(inputDir, "8-1.xml");
0286: File stylesheet = new File(inputDir, "namespaceparamtest.xsl");
0287: Builder builder = new Builder();
0288: Document stylesheetDoc = builder.build(stylesheet);
0289: XSLTransform xform = new XSLTransform(stylesheetDoc);
0290: xform.setParameter("test", "http://www.xom.nu/", new Double(2));
0291: xform.setParameter("test", "http://www.xom.nu/", null);
0292: Nodes output = xform.transform(builder.build(doc));
0293: assertEquals(1, output.size());
0294: Element result = (Element) output.get(0);
0295: assertEquals("<root xmlns:pre=\"http://www.xom.nu/\">1</root>",
0296: result.toXML());
0297:
0298: }
0299:
0300: public void testRemoveParameter() throws ParsingException,
0301: IOException, XSLException {
0302:
0303: File doc = new File(inputDir, "8-1.xml");
0304: File stylesheet = new File(inputDir, "paramtest.xsl");
0305: Builder builder = new Builder();
0306: Document stylesheetDoc = builder.build(stylesheet);
0307: XSLTransform xform = new XSLTransform(stylesheetDoc);
0308: xform.setParameter("test", new Double(2));
0309: xform.setParameter("test", null);
0310: Nodes output = xform.transform(builder.build(doc));
0311: assertEquals(1, output.size());
0312: Element result = (Element) output.get(0);
0313: assertEquals("<root>1</root>", result.toXML());
0314:
0315: }
0316:
0317: public void testTransformWithCFilter() throws ParsingException,
0318: IOException, XSLException {
0319:
0320: File doc = new File(inputDir, "8-1.xml");
0321: File stylesheet = new File(inputDir, "8-8.xsl");
0322: Builder builder = new Builder();
0323: Document stylesheetDoc = builder.build(stylesheet);
0324: XSLTransform xform = new XSLTransform(stylesheetDoc,
0325: new NodeFactoryTest.CFactory());
0326:
0327: Nodes output = xform.transform(builder.build(doc));
0328: assertEquals(1, output.size());
0329: Document result = new Document((Element) (output.get(0)));
0330:
0331: Document expected = builder.build("data/xslt/output/8-8c.xml");
0332: assertEquals(expected, result);
0333:
0334: }
0335:
0336: public void testCreateDocumentFragmentWithCommentFilter()
0337: throws ParsingException, IOException, XSLException {
0338:
0339: Element element1 = new Element("element1");
0340: element1.appendChild("some data and ");
0341: element1.appendChild(new Element("content"));
0342: element1.appendChild(" for a test");
0343:
0344: Element element2 = new Element("element2");
0345: element2
0346: .appendChild("Remember, the XSLT processor is going to strip out the literal white space");
0347: File doc = new File(inputDir, "8-14.xml");
0348: File stylesheet = new File(inputDir, "fragment.xsl");
0349: Builder builder = new Builder();
0350: Document stylesheetDoc = builder.build(stylesheet);
0351: XSLTransform xform = new XSLTransform(stylesheetDoc,
0352: new NodeFactoryTest.CommentFilter());
0353:
0354: Document input = builder.build(doc);
0355: Nodes output = xform.transform(input);
0356: assertEquals(5, output.size());
0357: assertEquals(element1, output.get(0));
0358: assertEquals(element2, output.get(1));
0359: assertEquals(new Element("element4"), output.get(3));
0360: assertEquals(new ProcessingInstruction("test",
0361: "PIs are not treated as literals in XSLT?"), output
0362: .get(4));
0363:
0364: }
0365:
0366: public void testCreateDocumentFragmentWithProcessingInstructionFilter()
0367: throws ParsingException, IOException, XSLException {
0368:
0369: Element element1 = new Element("element1");
0370: element1.appendChild("some data and ");
0371: element1.appendChild(new Element("content"));
0372: element1.appendChild(" for a test");
0373:
0374: Element element2 = new Element("element2");
0375: element2
0376: .appendChild("Remember, the XSLT processor is going to strip out the literal white space");
0377: File doc = new File(inputDir, "8-14.xml");
0378: File stylesheet = new File(inputDir, "fragment.xsl");
0379: Builder builder = new Builder();
0380: Document stylesheetDoc = builder.build(stylesheet);
0381: XSLTransform xform = new XSLTransform(stylesheetDoc,
0382: new NodeFactoryTest.ProcessingInstructionFilter());
0383:
0384: Document input = builder.build(doc);
0385: Nodes output = xform.transform(input);
0386: assertEquals(5, output.size());
0387: assertEquals(element1, output.get(0));
0388: assertEquals(element2, output.get(1));
0389: assertEquals(new Element("element4"), output.get(3));
0390: assertEquals(new Comment("test"), output.get(4));
0391:
0392: }
0393:
0394: public void testCreateDocumentFragmentWithUncommentFilter()
0395: throws ParsingException, IOException, XSLException {
0396:
0397: Element element1 = new Element("element1");
0398: element1.appendChild("some data and ");
0399: element1.appendChild(new Element("content"));
0400: element1.appendChild(" for a test");
0401:
0402: Element element2 = new Element("element2");
0403: element2
0404: .appendChild("Remember, the XSLT processor is going to strip out the literal white space");
0405: File doc = new File(inputDir, "8-14.xml");
0406: File stylesheet = new File(inputDir, "fragment.xsl");
0407: Builder builder = new Builder();
0408: Document stylesheetDoc = builder.build(stylesheet);
0409: XSLTransform xform = new XSLTransform(stylesheetDoc,
0410: new NodeFactoryTest.UncommentFilter());
0411:
0412: Document input = builder.build(doc);
0413: Nodes output = xform.transform(input);
0414: assertEquals(6, output.size());
0415: assertEquals(element1, output.get(0));
0416: assertEquals(element2, output.get(1));
0417: assertEquals(new Element("element4"), output.get(3));
0418: assertEquals(new Text("test"), output.get(4));
0419: assertEquals(new ProcessingInstruction("test",
0420: "PIs are not treated as literals in XSLT?"), output
0421: .get(5));
0422:
0423: }
0424:
0425: public void testTransform2() throws ParsingException, IOException,
0426: XSLException {
0427:
0428: File doc = new File(inputDir, "8-1.xml");
0429: File stylesheet = new File(inputDir, "8-12.xsl");
0430: Builder builder = new Builder();
0431: Document stylesheetDoc = builder.build(stylesheet);
0432: XSLTransform xform = new XSLTransform(stylesheetDoc);
0433: Nodes output = xform.transform(builder.build(doc));
0434: assertEquals(1, output.size());
0435: Document result = new Document((Element) (output.get(0)));
0436:
0437: Document expected = builder.build("data/xslt/output/8-12.xml");
0438: assertEquals(expected, result);
0439:
0440: }
0441:
0442: // For debugging
0443: private static void dumpResult(Document result, String filename)
0444: throws IOException {
0445:
0446: File debug = new File("data");
0447: debug = new File(debug, "xslt");
0448: debug = new File(debug, "debug/" + filename);
0449: OutputStream out = new FileOutputStream(debug);
0450: Serializer serializer = new Serializer(out);
0451: serializer.write(result);
0452: serializer.flush();
0453: out.close();
0454:
0455: }
0456:
0457: public void testTransformFromDocument() throws ParsingException,
0458: IOException, XSLException {
0459:
0460: File doc = new File(inputDir, "8-1.xml");
0461: Builder builder = new Builder();
0462: Document stylesheet = builder.build("data/xslt/input/8-12.xsl");
0463: XSLTransform xform = new XSLTransform(stylesheet);
0464: Nodes output = xform.transform(builder.build(doc));
0465: assertEquals(1, output.size());
0466: Document result = new Document((Element) (output.get(0)));
0467:
0468: Document expected = builder.build("data/xslt/output/8-12.xml");
0469: assertEquals(expected, result);
0470:
0471: }
0472:
0473: public void testTransformFromSystemID() throws ParsingException,
0474: IOException, XSLException {
0475:
0476: File doc = new File(inputDir, "8-1.xml");
0477: Builder builder = new Builder();
0478: String stylesheet = "data/xslt/input/8-12.xsl";
0479: Document stylesheetDoc = builder.build(stylesheet);
0480: XSLTransform xform = new XSLTransform(stylesheetDoc);
0481: Nodes output = xform.transform(builder.build(doc));
0482: assertEquals(1, output.size());
0483: Document result = new Document((Element) (output.get(0)));
0484:
0485: Document expected = builder.build("data/xslt/output/8-12.xml");
0486: assertEquals(expected, result);
0487:
0488: }
0489:
0490: public void testTransformWithNamespaces() throws ParsingException,
0491: IOException, XSLException {
0492:
0493: File doc = new File(inputDir, "8-14.xml");
0494: File stylesheet = new File(inputDir, "8-15.xsl");
0495: Builder builder = new Builder();
0496: Document stylesheetDoc = builder.build(stylesheet);
0497: XSLTransform xform = new XSLTransform(stylesheetDoc);
0498: Document input = builder.build(doc);
0499: Nodes output = xform.transform(input);
0500: assertEquals(1, output.size());
0501: Document result = new Document((Element) (output.get(0)));
0502:
0503: Document expected = builder.build("data/xslt/output/8-15.xml");
0504: assertEquals(expected, result);
0505:
0506: }
0507:
0508: public void testSingleTextNode() throws ParsingException,
0509: IOException, XSLException {
0510:
0511: File doc = new File(inputDir, "8-14.xml");
0512: File stylesheet = new File(inputDir, "singlestring.xsl");
0513: Builder builder = new Builder();
0514: Document stylesheetDoc = builder.build(stylesheet);
0515: XSLTransform xform = new XSLTransform(stylesheetDoc);
0516: Document input = builder.build(doc);
0517: Nodes output = xform.transform(input);
0518: assertEquals(1, output.size());
0519: Text data = (Text) (output.get(0));
0520: assertEquals("Data", data.getValue());
0521:
0522: }
0523:
0524: public void testToString() throws XSLException, ParsingException,
0525: IOException {
0526:
0527: File stylesheet = new File(inputDir, "singlestring.xsl");
0528: Builder builder = new Builder();
0529: Document stylesheetDoc = builder.build(stylesheet);
0530: XSLTransform xform = new XSLTransform(stylesheetDoc);
0531: assertTrue(xform.toString().startsWith(
0532: "[nu.xom.xslt.XSLTransform: "));
0533:
0534: }
0535:
0536: // Make sure that method="text" doesn't affect what we get
0537: // since this is not a serialized transform
0538: // See http://issues.apache.org/bugzilla/show_bug.cgi?id=30197
0539: public void testTextMethod() throws ParsingException, IOException,
0540: XSLException {
0541:
0542: File doc = new File(inputDir, "8-14.xml");
0543: File stylesheet = new File(inputDir, "textmethod.xsl");
0544: Builder builder = new Builder();
0545: Document stylesheetDoc = builder.build(stylesheet);
0546: XSLTransform xform = new XSLTransform(stylesheetDoc);
0547: Document input = builder.build(doc);
0548: Nodes output = xform.transform(input);
0549: assertEquals(6, output.size());
0550: assertEquals("12345", output.get(0).getValue());
0551: assertEquals("67890", output.get(1).getValue());
0552: assertEquals("", output.get(2).getValue());
0553: assertEquals("0987654321", output.get(3).getValue());
0554: assertTrue(output.get(4) instanceof Comment);
0555: assertTrue(output.get(5) instanceof ProcessingInstruction);
0556:
0557: }
0558:
0559: public void testCommentWithParent() throws XSLException,
0560: ParsingException, IOException {
0561:
0562: Builder builder = new Builder();
0563: File stylesheet = new File(inputDir, "commentwithparent.xsl");
0564: Document stylesheetDoc = builder.build(stylesheet);
0565: XSLTransform xform = new XSLTransform(stylesheetDoc);
0566: Document input = new Document(new Element("root"));
0567: Nodes output = xform.transform(input);
0568: assertEquals(1, output.size());
0569: assertEquals("", output.get(0).getValue());
0570: Element root = (Element) output.get(0);
0571: assertEquals(1, root.getChildCount());
0572: Comment child = (Comment) root.getChild(0);
0573: assertEquals("test", child.getValue());
0574:
0575: }
0576:
0577: public void testProcessingInstructionWithParent()
0578: throws XSLException, ParsingException, IOException {
0579:
0580: Builder builder = new Builder();
0581: File stylesheet = new File(inputDir, "piwithparent.xsl");
0582: Document stylesheetDoc = builder.build(stylesheet);
0583: XSLTransform xform = new XSLTransform(stylesheetDoc);
0584: Document input = new Document(new Element("root"));
0585: Nodes output = xform.transform(input);
0586: assertEquals(1, output.size());
0587: assertEquals("", output.get(0).getValue());
0588: Element root = (Element) output.get(0);
0589: assertEquals(1, root.getChildCount());
0590: ProcessingInstruction child = (ProcessingInstruction) root
0591: .getChild(0);
0592: assertEquals("target", child.getTarget());
0593: assertEquals("test", child.getValue());
0594:
0595: }
0596:
0597: public void testTransformNodes() throws XSLException,
0598: ParsingException, IOException {
0599:
0600: File stylesheet = new File(inputDir, "piwithparent.xsl");
0601: Builder builder = new Builder();
0602: Nodes input = new Nodes(new Element("root"));
0603: Document stylesheetDoc = builder.build(stylesheet);
0604: XSLTransform xform = new XSLTransform(stylesheetDoc);
0605: Nodes output = xform.transform(input);
0606: assertEquals(1, output.size());
0607: assertEquals("", output.get(0).getValue());
0608: Element root = (Element) output.get(0);
0609: assertEquals(1, root.getChildCount());
0610: ProcessingInstruction child = (ProcessingInstruction) root
0611: .getChild(0);
0612: assertEquals("target", child.getTarget());
0613: assertEquals("test", child.getValue());
0614:
0615: }
0616:
0617: public void testCopyXMLBaseAttribute() throws XSLException,
0618: ParsingException, IOException {
0619:
0620: File stylesheet = new File(inputDir, "id_transform.xsl");
0621: Builder builder = new Builder();
0622: Element root = new Element("root");
0623: root.addAttribute(new Attribute("xml:base",
0624: Namespace.XML_NAMESPACE, "http://www.example.org/"));
0625: Document input = new Document(root);
0626: Document stylesheetDoc = builder.build(stylesheet);
0627: XSLTransform xform = new XSLTransform(stylesheetDoc);
0628: Nodes output = xform.transform(input);
0629: assertEquals(1, output.size());
0630: assertEquals("", output.get(0).getValue());
0631: Element rootOut = (Element) output.get(0);
0632: assertEquals(0, rootOut.getChildCount());
0633: assertEquals(1, rootOut.getAttributeCount());
0634: assertEquals("http://www.example.org/", rootOut.getBaseURI());
0635:
0636: }
0637:
0638: public void testCopyXMLLangAttribute() throws XSLException,
0639: ParsingException, IOException {
0640:
0641: File stylesheet = new File(inputDir, "id_transform.xsl");
0642: Builder builder = new Builder();
0643: Element root = new Element("root");
0644: root.addAttribute(new Attribute("xml:lang",
0645: Namespace.XML_NAMESPACE, "http://www.example.org/"));
0646: Document input = new Document(root);
0647: Document stylesheetDoc = builder.build(stylesheet);
0648: XSLTransform xform = new XSLTransform(stylesheetDoc);
0649: Nodes output = xform.transform(input);
0650: assertEquals(1, output.size());
0651: assertEquals("", output.get(0).getValue());
0652: Element rootOut = (Element) output.get(0);
0653: assertEquals(0, rootOut.getChildCount());
0654: assertEquals(1, rootOut.getAttributeCount());
0655:
0656: }
0657:
0658: public void testTriple() throws IOException, ParsingException,
0659: XSLException {
0660:
0661: File stylesheet = new File(inputDir, "identity.xsl");
0662: Builder builder = new Builder();
0663: Document stylesheetDoc = builder.build(stylesheet);
0664: XSLTransform xform = new XSLTransform(stylesheetDoc,
0665: new NodeFactoryTest.TripleElementFilter());
0666:
0667: String data = "<a><b><c/></b></a>";
0668: Document doc = builder.build(data, "http://www.example.org/");
0669:
0670: Nodes result = xform.transform(doc);
0671:
0672: assertEquals(3, result.size());
0673: assertEquals(result.get(0), result.get(1));
0674: assertEquals(result.get(1), result.get(2));
0675: Element a = (Element) result.get(2);
0676: assertEquals("a", a.getLocalName());
0677: assertEquals(3, a.getChildCount());
0678: assertEquals(0, a.getAttributeCount());
0679: Element b = (Element) a.getChild(1);
0680: assertEquals(3, b.getChildCount());
0681: assertEquals("b", b.getLocalName());
0682:
0683: }
0684:
0685: public void testPassingNullSetsDefaultFactory() throws IOException,
0686: ParsingException, XSLException {
0687:
0688: File stylesheet = new File(inputDir, "identity.xsl");
0689: Builder builder = new Builder();
0690: Document stylesheetDoc = builder.build(stylesheet);
0691: XSLTransform xform = new XSLTransform(stylesheetDoc, null);
0692:
0693: String data = "<a><b><c/></b></a>";
0694: Document doc = builder.build(data, "http://www.example.org/");
0695:
0696: Nodes result = xform.transform(doc);
0697:
0698: assertEquals(1, result.size());
0699: Element a = (Element) result.get(0);
0700: assertEquals("a", a.getLocalName());
0701: assertEquals(1, a.getChildCount());
0702: assertEquals(0, a.getAttributeCount());
0703: Element b = (Element) a.getChild(0);
0704: assertEquals(1, b.getChildCount());
0705: assertEquals("b", b.getLocalName());
0706:
0707: }
0708:
0709: public void testTransformEmptyNodesList() throws IOException,
0710: ParsingException, XSLException {
0711:
0712: File stylesheet = new File(inputDir, "identity.xsl");
0713: Builder builder = new Builder();
0714: Document stylesheetDoc = builder.build(stylesheet);
0715: XSLTransform xform = new XSLTransform(stylesheetDoc);
0716:
0717: Nodes result = xform.transform(new Nodes());
0718:
0719: assertEquals(0, result.size());
0720:
0721: }
0722:
0723: public void testMinimizingFactory() throws XSLException,
0724: ParsingException, IOException {
0725:
0726: File stylesheet = new File(inputDir, "identity.xsl");
0727: Builder builder = new Builder();
0728: Document stylesheetDoc = builder.build(stylesheet);
0729: XSLTransform xform = new XSLTransform(stylesheetDoc,
0730: new NodeFactoryTest.MinimizingFactory());
0731:
0732: Document input = builder.build("<!-- test--><test>"
0733: + "<em>data</em>\r\n<span>test</span></test>"
0734: + "<?target data?>", "http://example.org/");
0735: Nodes output = xform.transform(input);
0736: assertEquals(0, output.size());
0737:
0738: }
0739:
0740: public void testIllegalTransform() throws XSLException,
0741: ParsingException, IOException {
0742:
0743: File stylesheet = new File(inputDir, "illegaltransform.xsl");
0744: Builder builder = new Builder();
0745: Document stylesheetDoc = builder.build(stylesheet);
0746: XSLTransform xform = new XSLTransform(stylesheetDoc);
0747: Element root = new Element("root", "http://www.example.org");
0748: Document input = new Document(root);
0749: try {
0750: xform.transform(input);
0751: fail("Allowed illegal transform");
0752: } catch (XSLException ex) {
0753: assertNotNull(ex.getMessage());
0754: }
0755:
0756: }
0757:
0758: public void testRemapPrefixToSameURI() throws IOException,
0759: ParsingException, XSLException {
0760:
0761: File stylesheet = new File(inputDir, "identity.xsl");
0762: Builder builder = new Builder();
0763: Document stylesheetDoc = builder.build(stylesheet);
0764: XSLTransform xform = new XSLTransform(stylesheetDoc);
0765:
0766: String data = "<a xmlns:pre='http://www.example.org/'>"
0767: + "<b xmlns:pre='http://www.example.org/'>in B</b></a>";
0768: Document doc = builder.build(data, "http://www.example.org/");
0769:
0770: Nodes result = xform.transform(doc);
0771:
0772: assertEquals(doc.getRootElement(), result.get(0));
0773:
0774: }
0775:
0776: public void testElementsToAttributes() throws IOException,
0777: ParsingException, XSLException {
0778:
0779: File stylesheet = new File(inputDir, "identity.xsl");
0780: Builder builder = new Builder();
0781: Document stylesheetDoc = builder.build(stylesheet);
0782: XSLTransform xform = new XSLTransform(stylesheetDoc,
0783: new AttributeFactory());
0784:
0785: String data = "<a><b>in B<c>in C</c></b></a>";
0786: Document doc = builder.build(data, "http://www.example.org/");
0787:
0788: Nodes result = xform.transform(doc);
0789:
0790: assertEquals(1, result.size());
0791: Element a = (Element) result.get(0);
0792: assertEquals("a", a.getLocalName());
0793: assertEquals(0, a.getChildCount());
0794: assertEquals(1, a.getAttributeCount());
0795: assertEquals("in B", a.getAttribute("b").getValue());
0796:
0797: }
0798:
0799: private static class AttributeFactory extends NodeFactory {
0800:
0801: public Nodes finishMakingElement(Element element) {
0802: ParentNode parent = element.getParent();
0803: if (parent == null || parent instanceof Document) {
0804: return new Nodes(element);
0805: }
0806: return new Nodes(new Attribute(element.getQualifiedName(),
0807: element.getNamespaceURI(), element.getValue()));
0808: }
0809:
0810: }
0811:
0812: public void testAttributesToElements() throws IOException,
0813: ParsingException, XSLException {
0814:
0815: File stylesheet = new File(inputDir, "identity.xsl");
0816: Builder builder = new Builder();
0817: Document stylesheetDoc = builder.build(stylesheet);
0818: XSLTransform xform = new XSLTransform(stylesheetDoc,
0819: new AttributesToElements());
0820:
0821: String data = "<a name='value'><b x='y' a='b'/></a>";
0822: Document doc = builder.build(data, "http://www.example.org/");
0823:
0824: Nodes result = xform.transform(doc);
0825:
0826: assertEquals(1, result.size());
0827: Element a = (Element) result.get(0);
0828: assertEquals("a", a.getLocalName());
0829: assertEquals(2, a.getChildCount());
0830: assertEquals(0, a.getAttributeCount());
0831: Element name = (Element) a.getChild(0);
0832: assertEquals("name", name.getLocalName());
0833: assertEquals("value", name.getValue());
0834: Element b = (Element) a.getChild(1);
0835: assertEquals("b", b.getLocalName());
0836: assertEquals(2, b.getChildCount());
0837: assertEquals("y", b.getFirstChildElement("x").getValue());
0838: assertEquals("b", b.getFirstChildElement("a").getValue());
0839:
0840: }
0841:
0842: private static class AttributesToElements extends NodeFactory {
0843:
0844: public Nodes makeAttribute(String name, String URI,
0845: String value, Attribute.Type type) {
0846: Element element = new Element(name, URI);
0847: element.appendChild(value);
0848: return new Nodes(element);
0849: }
0850:
0851: }
0852:
0853: public void testCommentsAreTransformed() throws IOException,
0854: ParsingException, XSLException {
0855:
0856: File stylesheet = new File(inputDir, "identity.xsl");
0857: Builder builder = new Builder();
0858: Document stylesheetDoc = builder.build(stylesheet);
0859: XSLTransform xform = new XSLTransform(stylesheetDoc);
0860:
0861: String data = "<a><!--test--></a>";
0862: Document doc = builder.build(data, "http://www.example.org/");
0863:
0864: Nodes result = xform.transform(doc);
0865:
0866: assertEquals(1, result.size());
0867: Element a = (Element) result.get(0);
0868: assertEquals("a", a.getLocalName());
0869: assertEquals(1, a.getChildCount());
0870: assertEquals(0, a.getAttributeCount());
0871: Node child = a.getChild(0);
0872: assertTrue(child instanceof Comment);
0873: assertTrue(child.getValue().equals("test"));
0874:
0875: }
0876:
0877: public void testCommentToAttribute() throws IOException,
0878: ParsingException, XSLException {
0879:
0880: File stylesheet = new File(inputDir, "identity.xsl");
0881: Builder builder = new Builder();
0882: Document stylesheetDoc = builder.build(stylesheet);
0883: XSLTransform xform = new XSLTransform(stylesheetDoc,
0884: new NodeFactory() {
0885: public Nodes makeComment(String text) {
0886: return new Nodes(new Attribute("comment", text));
0887: }
0888: });
0889:
0890: String data = "<a><!--test--></a>";
0891: Document doc = builder.build(data, "http://www.example.org/");
0892:
0893: Nodes result = xform.transform(doc);
0894:
0895: assertEquals(1, result.size());
0896: Element a = (Element) result.get(0);
0897: assertEquals("a", a.getLocalName());
0898: assertEquals(0, a.getChildCount());
0899: assertEquals(1, a.getAttributeCount());
0900: Attribute comment = a.getAttribute(0);
0901: assertEquals("comment", comment.getLocalName());
0902: assertEquals("test", comment.getValue());
0903:
0904: }
0905:
0906: public void testAdditionalDefaultNamespace() throws IOException,
0907: ParsingException, XSLException {
0908:
0909: File stylesheet = new File(inputDir, "identity.xsl");
0910: Builder builder = new Builder();
0911: Document stylesheetDoc = builder.build(stylesheet);
0912: XSLTransform xform = new XSLTransform(stylesheetDoc);
0913:
0914: String data = "<pre:a xmlns:pre='http://www.example.org' "
0915: + "xmlns='http://www.example.net'>data</pre:a>";
0916: Document doc = builder.build(data, "http://www.example.org/");
0917:
0918: Nodes result = xform.transform(doc);
0919:
0920: assertEquals(1, result.size());
0921: Element a = (Element) result.get(0);
0922: assertEquals("a", a.getLocalName());
0923: assertEquals("pre:a", a.getQualifiedName());
0924: assertEquals("data", a.getValue());
0925: assertEquals("http://www.example.org", a.getNamespaceURI("pre"));
0926: assertEquals("http://www.example.net", a.getNamespaceURI(""));
0927: assertEquals(2, a.getNamespaceDeclarationCount());
0928:
0929: }
0930:
0931: private static boolean indentYes(Document styleDoc) {
0932:
0933: Element output = styleDoc.getRootElement()
0934: .getFirstChildElement("output",
0935: "http://www.w3.org/1999/XSL/Transform");
0936: if (output == null)
0937: return false;
0938:
0939: String indent = output.getAttributeValue("indent");
0940: if ("yes".equals(indent)) {
0941: return true;
0942: } else
0943: return false;
0944:
0945: }
0946:
0947: private static class StrippingFactory extends NodeFactory {
0948:
0949: public Nodes makeText(String s) {
0950:
0951: String stripped = stripSpace(s);
0952: if (stripped.length() == 0)
0953: return new Nodes();
0954: Text result = new Text(stripped);
0955: return new Nodes(result);
0956: }
0957:
0958: public Nodes makeAttribute(String name, String URI,
0959: String value, Attribute.Type type) {
0960: return new Nodes(new Attribute(name, URI,
0961: stripSpace(value), type));
0962: }
0963:
0964: private String stripSpace(String s) {
0965:
0966: StringBuffer sb = new StringBuffer();
0967: for (int i = 0; i < s.length(); i++) {
0968: if (!Character.isWhitespace(s.charAt(i))) {
0969: sb.append(s.charAt(i));
0970: }
0971: }
0972:
0973: return sb.toString();
0974:
0975: }
0976:
0977: }
0978:
0979: // XXX need to upgrade to final release of XSLT test suites
0980: // and then split into individual tests
0981: public void testOASISXalanConformanceSuite() throws IOException,
0982: ParsingException, XSLException {
0983:
0984: Builder builder = new Builder();
0985: NodeFactory stripper = new StrippingFactory();
0986: Builder strippingBuilder = new Builder(stripper);
0987:
0988: File base = new File("data");
0989: base = new File(base, "oasis-xslt-testsuite");
0990: base = new File(base, "TESTS");
0991: base = new File(base, "Xalan_Conformance_Tests");
0992: File catalog = new File(base, "catalog.xml");
0993:
0994: // The test suite need to be installed separately. If we can't
0995: // find the catalog, we just don't run these tests.
0996: if (catalog.exists()) {
0997: Document doc = builder.build(catalog);
0998: Element testsuite = doc.getRootElement();
0999: Elements submitters = testsuite
1000: .getChildElements("test-catalog");
1001: for (int i = 0; i < submitters.size(); i++) {
1002: Element submitter = submitters.get(i);
1003: Elements testcases = submitter
1004: .getChildElements("test-case");
1005: for (int j = 0; j < testcases.size(); j++) {
1006:
1007: Element testcase = testcases.get(j);
1008: String id = testcase.getAttributeValue("id");
1009: if (id.startsWith("output_")) {
1010: // These test cases are mostly about producing
1011: // HTML and plain text output that isn't
1012: // relevant to XOM
1013: continue;
1014: }
1015: File root = new File(base, testcase
1016: .getFirstChildElement("file-path")
1017: .getValue());
1018: File input = null;
1019: File style = null;
1020: File output = null;
1021: Element scenario = testcase
1022: .getFirstChildElement("scenario");
1023: Elements inputs = scenario
1024: .getChildElements("input-file");
1025: for (int k = 0; k < inputs.size(); k++) {
1026: Element file = inputs.get(k);
1027: String role = file.getAttributeValue("role");
1028: if ("principal-data".equals(role)) {
1029: input = new File(root, file.getValue());
1030: } else if ("principal-stylesheet".equals(role)) {
1031: style = new File(root, file.getValue());
1032: }
1033: }
1034: Elements outputs = scenario
1035: .getChildElements("output-file");
1036: for (int k = 0; k < outputs.size(); k++) {
1037: Element file = outputs.get(k);
1038: String role = file.getAttributeValue("role");
1039: if ("principal".equals(role)) {
1040: // Fix up OASIS catalog bugs
1041: File parent = new File(root.getParent());
1042: parent = new File(parent, "REF_OUT");
1043: parent = new File(parent, root.getName());
1044: String outputFileName = file.getValue();
1045: output = new File(parent, outputFileName);
1046: }
1047: }
1048:
1049: try {
1050: Document inputDoc = builder.build(input);
1051: Document styleDoc = builder.build(style);
1052: // If the transform specifies indent="yes".
1053: // we remove all white space before comparing
1054: XSLTransform xform;
1055: if (indentYes(styleDoc)) {
1056: xform = new XSLTransform(styleDoc, stripper);
1057: } else
1058: xform = new XSLTransform(styleDoc);
1059: Nodes result = xform.transform(inputDoc);
1060: if (output == null) {
1061: // transform should have failed
1062: fail("Transformed " + id);
1063: } else {
1064: try {
1065: Document expectedResult;
1066: if (indentYes(styleDoc)) {
1067: expectedResult = strippingBuilder
1068: .build(output);
1069: } else {
1070: expectedResult = builder
1071: .build(output);
1072: }
1073: Document actualResult = XSLTransform
1074: .toDocument(result);
1075:
1076: if (id.equals("attribset_attribset40")) {
1077: // This test does not necessarily
1078: // produce an identical infoset due
1079: // to necessary remapping of
1080: // namespace prefixes.
1081: continue;
1082: } else if (id.equals("axes_axes129")) {
1083: // Xalan bug. Fixed in more recent
1084: // version than bundled with the JDK 1.4.2_05
1085: } else if (id.equals("copy_copy56")
1086: || id.equals("copy_copy58")
1087: || id.equals("copy_copy60")
1088: || id.equals("copy_copy59")) {
1089: // Xalan bug;
1090: // See http://issues.apache.org/jira/browse/XALANJ-1081
1091: // Also see erratum E27 to the XSLT spec.
1092: } else if (id
1093: .equals("expression_expression02")) {
1094: // requires unparsed entities XOM doesn't support
1095: } else if (id.equals("idkey_idkey31")) {
1096: // Known Xalan bug
1097: // See http://issues.apache.org/jira/browse/XALANJ-1325
1098: } else if (id.equals("idkey_idkey61")
1099: || id.equals("idkey_idkey62")) {
1100: // Xalan bug. Fixed in more recent
1101: // version than bundled with the JDK 1.4.2_05
1102: // See http://issues.apache.org/jira/browse/XALANJ-1318
1103: } else if (id
1104: .equals("impincl_impincl11")) {
1105: // Test case bug; reported 2004-09-18
1106: // See http://lists.oasis-open.org/archives/xslt-conformance-comment/200409/msg00001.html
1107: } else if (id.equals("math_math110")
1108: || id.equals("math_math111")) {
1109: // Xalan bug. Fixed in more recent
1110: // version than bundled with the JDK 1.4.2_05
1111: // See http://issues.apache.org/jira/browse/XALANJ-1278
1112: } else if (id
1113: .equals("numbering_numbering17")
1114: || id
1115: .equals("numbering_numbering79")) {
1116: // test suite bug per XSLT 1.0 erratum 24. See
1117: // See http://issues.apache.org/jira/browse/XALANJ-1979
1118: } else if (id
1119: .equals("position_position104")) {
1120: // Xalan bug. Fixed in more recent
1121: // version than bundled with the JDK 1.4.2_05
1122: } else if (id
1123: .equals("position_position106")) {
1124: // Xalan bug. Fixed in more recent
1125: // version than bundled with the JDK 1.4.2_05
1126: } else if (id
1127: .equals("position_position107")
1128: || id
1129: .equals("position_position109")) {
1130: // Xalan bug. Fixed in more recent
1131: // version than bundled with the JDK 1.4.2_05
1132: // See http://issues.apache.org/jira/browse/XALANJ-1289
1133: } else {
1134: assertEquals("Problem with " + id,
1135: expectedResult,
1136: actualResult);
1137: }
1138: } catch (ParsingException ex) {
1139: // a few of the test cases generate
1140: // text or HTML output rather than
1141: // well-formed XML. For the moment, I
1142: // just skip these.
1143: continue;
1144: } catch (IllegalAddException ex) {
1145: // A few of the test cases generate
1146: // incomplete documents so we can't
1147: // compare output. Perhaps I could
1148: // wrap in an element, then get children
1149: // to build a Nodes object rather than a
1150: // Document???? i.e. a fragment parser?
1151: // Could use a SequenceInputStream to hack this
1152: }
1153: }
1154:
1155: } catch (ParsingException ex) {
1156: // Some of the test cases contain relative
1157: // namespace URIs XOM does not support
1158: if (ex.getCause() instanceof MalformedURIException)
1159: continue;
1160: throw ex;
1161: } catch (XSLException ex) {
1162: // If the output was null the transformation
1163: // was expected to fail
1164: if (output != null) {
1165: // a few of the test cases use relative namespace URIs
1166: // XOM doesn't support
1167: Throwable cause = ex.getCause();
1168: if (cause instanceof MalformedURIException) {
1169: continue;
1170: }
1171:
1172: if ("impincl_impincl27".equals(id)) {
1173: // Test case uses file: URI XOM doesn't support
1174: continue;
1175: } else if ("numberformat_numberformat45"
1176: .equals(id)
1177: || "numberformat_numberformat46"
1178: .equals(id)) {
1179: // This has been fixed in Xalan 2.5.2.
1180: // However, it's a bug in earlier versions of Xalan
1181: // including the one bundled with the JDK 1.4.2_05
1182: // See http://issues.apache.org/jira/browse/XALANJ-805
1183: // XXX I think this might need an updated version of the test cases
1184: // and expected output at this point.
1185: continue;
1186: }
1187:
1188: System.out.println(id);
1189: System.out.println(ex.getMessage());
1190: throw ex;
1191: }
1192: }
1193:
1194: }
1195: }
1196:
1197: }
1198:
1199: }
1200:
1201: public void testOASISMicrosoftConformanceSuite()
1202: throws IOException, ParsingException, XSLException {
1203:
1204: Builder builder = new Builder();
1205: NodeFactory stripper = new StrippingFactory();
1206: Builder strippingBuilder = new Builder(stripper);
1207: File base = new File("data");
1208: base = new File(base, "oasis-xslt-testsuite");
1209: base = new File(base, "TESTS");
1210: File catalog = new File(base, "catalog.xml");
1211:
1212: // The test suite need to be installed separately. If we can't
1213: // find the catalog, we just don't run these tests.
1214: if (catalog.exists()) {
1215: Document doc = builder.build(catalog);
1216: Element testsuite = doc.getRootElement();
1217: Elements submitters = testsuite
1218: .getChildElements("test-catalog");
1219: Element submitter = submitters.get(1);
1220: Elements testcases = submitter
1221: .getChildElements("test-case");
1222: for (int j = 0; j < testcases.size(); j++) {
1223: Element testcase = testcases.get(j);
1224: String id = testcase.getAttributeValue("id");
1225: File root = new File(base, "MSFT_Conformance_Tests");
1226: root = new File(root, testcase.getFirstChildElement(
1227: "file-path").getValue());
1228: File input = null;
1229: File style = null;
1230: File output = null;
1231: Element scenario = testcase
1232: .getFirstChildElement("scenario");
1233: Elements inputs = scenario
1234: .getChildElements("input-file");
1235: for (int k = 0; k < inputs.size(); k++) {
1236: Element file = inputs.get(k);
1237: String role = file.getAttributeValue("role");
1238: if ("principal-data".equals(role)) {
1239: input = new File(root, file.getValue());
1240: } else if ("principal-stylesheet".equals(role)) {
1241: style = new File(root, file.getValue());
1242: }
1243: } // end for
1244: Elements outputs = scenario
1245: .getChildElements("output-file");
1246: for (int k = 0; k < outputs.size(); k++) {
1247: Element file = outputs.get(k);
1248: String role = file.getAttributeValue("role");
1249: if ("principal".equals(role)) {
1250: // Fix up OASIS catalog bugs
1251: File parent = new File(root.getParent());
1252: parent = new File(parent, "REF_OUT");
1253: parent = new File(parent, root.getName());
1254: String outputFileName = file.getValue();
1255: output = new File(parent, outputFileName);
1256: }
1257: } // end for
1258:
1259: try {
1260: Document styleDoc = builder.build(style);
1261: boolean strip = indentYes(styleDoc);
1262: if ("BVTs_bvt002".equals(id)
1263: || "BVTs_bvt077".equals(id)) {
1264: // This has been fixed at least as of Xalan 2.6.0.
1265: // However, it's a bug in earlier versions of Xalan
1266: // including the one bundled with the JDK 1.4.2_05
1267: continue;
1268: } else if ("XSLTFunctions_Bug76984".equals(id)) {
1269: // This has been fixed at least as of Xalan 2.6.0.
1270: // However, it's a bug in earlier versions of Xalan
1271: // including the one bundled with the JDK 1.4.2_05
1272: continue;
1273: } else if ("BVTs_bvt020".equals(id)
1274: || "BVTs_bvt022".equals(id)
1275: || "BVTs_bvt024".equals(id)
1276: || "BVTs_bvt058".equals(id)) {
1277: // Either a test suite bug, or a recoverable
1278: // error Xalan doesn't recover from.
1279: continue;
1280: } else if ("BVTs_bvt038".equals(id)
1281: || "Namespace-alias__91785".equals(id)
1282: || "Namespace-alias__91786".equals(id)) {
1283: // a recoverable error Xalan doesn't recover from properly
1284: // http://issues.apache.org/jira/browse/XALANJ-1957
1285: continue;
1286: } else if ("Namespace_XPath_CopyNamespaceNodeToOutput"
1287: .equals(id)) {
1288: // Xalan bug
1289: // http://issues.apache.org/jira/browse/XALANJ-1959
1290: continue;
1291: } else if ("Namespace-alias_Namespace-Alias_WithinRTF"
1292: .equals(id)) {
1293: // Xalan bug
1294: // http://issues.apache.org/jira/browse/XALANJ-1960
1295: continue;
1296: } else if ("Completeness__84361".equals(id)
1297: || "Namespace-alias__91781".equals(id)
1298: || "Namespace-alias__91782".equals(id)
1299: || "Namespace-alias_Namespace-Alias_Test1"
1300: .equals(id)
1301: || "Namespace-alias_Namespace-Alias_Test2"
1302: .equals(id)) {
1303: // a recoverable error Xalan doesn't recover from
1304: continue;
1305: } else if ("Output__84008".equals(id)) {
1306: // a recoverable error Xalan doesn't recover from
1307: continue;
1308: } else if ("XSLTFunctions_ElementAvailFunctionFalseTest"
1309: .equals(id)) {
1310: // Xalan bug
1311: // http://issues.apache.org/jira/browse/XALANJ-1961
1312: continue;
1313: } else if ("XSLTFunctions_GenereateIdAppliedToNamespaceNodesOnDifferentElements"
1314: .equals(id)) {
1315: // Xalan bug
1316: // http://issues.apache.org/jira/browse/XALANJ-1962
1317: continue;
1318: } else if ("XSLTFunctions__specialCharInPattern"
1319: .equals(id)) {
1320: // a recoverable error Xalan doesn't recover from
1321: continue;
1322: } else if ("XSLTFunctions_DocumentFunctionWithAbsoluteArgument"
1323: .equals(id)) {
1324: // test case bug; bad URL passed to document function
1325: continue;
1326: } else if ("BVTs_bvt052".equals(id)
1327: || "Keys_PerfRepro2".equals(id)) {
1328: // Requires a non-standard extension function
1329: continue;
1330: } else if ("BVTs_bvt044".equals(id)) {
1331: // a recoverable error Xalan doesn't recover from
1332: // http://issues.apache.org/jira/browse/XALANJ-1957
1333: continue;
1334: } else if ("BVTs_bvt039".equals(id)) {
1335: // Xalan bug
1336: continue;
1337: } else if ("BVTs_bvt033".equals(id)
1338: || "BVTs_bvt034".equals(id)) {
1339: // Test suite bug; 2.0 is not unrecognized
1340: continue;
1341: } else if ("Text__78274".equals(id)
1342: || "Text__78276".equals(id)) {
1343: // Test suite bug; no xsl:preserve-space attribute
1344: continue;
1345: } else if ("XSLTFunctions__minimumValue".equals(id)
1346: || "XSLTFunctions__minimalValue".equals(id)) {
1347: // test suite bug
1348: continue;
1349: } else if ("Errors_err073".equals(id)) {
1350: // Xalan bug: StackOverflowError
1351: continue;
1352: } else if ("Sorting_SortExprWithCurrentInsideForEach1"
1353: .equals(id)) {
1354: // Xalan bug
1355: // http://issues.apache.org/jira/browse/XALANJ-1970
1356: continue;
1357: } else if ("BVTs_bvt041".equals(id)
1358: || "BVTs_bvt063".equals(id)
1359: || "BVTs_bvt070".equals(id)) {
1360: // Xalan bundled with JDK 1.4.2_05 does not recover
1361: // from this error involving multiple conflicting
1362: // xsl:output at same import precedence, though
1363: // 2.6.0 does
1364: continue;
1365: }
1366: Document inputDoc = builder.build(input);
1367: XSLTransform xform;
1368: if (strip)
1369: xform = new XSLTransform(styleDoc, stripper);
1370: else
1371: xform = new XSLTransform(styleDoc);
1372: Nodes result = xform.transform(inputDoc);
1373: if (output == null) {
1374: if ("Attributes__89463".equals(id)
1375: || "Attributes__89465".equals(id)) {
1376: // Processors are allowed to recover from
1377: // this problem.
1378: assertEquals(0, result.size());
1379: } else if ("Attributes__89464".equals(id)) {
1380: // Processors are allowed to recover from
1381: // this problem.
1382: assertEquals(0, ((Element) result.get(0))
1383: .getAttributeCount());
1384: } else if ("Namespace-alias__91772".equals(id)
1385: || "Namespace-alias__91774".equals(id)
1386: || "Namespace-alias__91780".equals(id)
1387: || "Namespace-alias__91790".equals(id)
1388: || "Namespace-alias__91791".equals(id)
1389: || "Sorting__84006".equals(id)
1390: || "Sorting__91754".equals(id)) {
1391: // Processors are allowed to recover from
1392: // this problem.
1393: continue;
1394: } else if (id.startsWith("Errors_")) {
1395: // Processors are allowed to recover from
1396: // most of these problems.
1397: } else if (id.startsWith("FormatNumber")) {
1398: // Processors are allowed to recover from
1399: // most of these problems.
1400: } else if ("BVTs_bvt074".equals(id)) {
1401: // Processors are allowed to recover from
1402: // this problem.
1403: assertEquals(0, result.get(0)
1404: .getChildCount());
1405: } else if ("XSLTFunctions__currency".equals(id)
1406: || "XSLTFunctions__mixingInvalids"
1407: .equals(id)) {
1408: // Processors are allowed to recover from
1409: // this problem.
1410: continue;
1411: } else if ("Attributes_Attribute_UseXmlnsNsAsNamespaceForAttribute"
1412: .equals(id)
1413: || "Attributes_Attribute_UseXmlnsAsNamespaceForAttributeImplicitly"
1414: .equals(id)
1415: || "Elements_Element_UseXslElementWithNameSpaceAttrEqualToXmlnsUri"
1416: .equalsIgnoreCase(id)
1417: || "Elements_Element_UseXslElementWithNameSpaceEqualToXmlnsUri"
1418: .equalsIgnoreCase(id)) {
1419: // test follows namespace errata we don't accept
1420: } else if ("AttributeSets_RefToUndefinedAttributeSet"
1421: .equals(id)) {
1422: // I think the test case is wrong; I see
1423: // nothing in the spec that says this is
1424: // an error.
1425: } else if ("Namespace__77665".equals(id)
1426: || "Namespace__77675".equals(id)) {
1427: // I think the test case is wrong; I see
1428: // nothing in the spec that says this is
1429: // an error. See
1430: // http://lists.oasis-open.org/archives/xslt-conformance-comment/200409/msg00007.html
1431: } else if ("Variables__84633".equals(id)
1432: || "Variables__84634".equals(id)
1433: || "Variables__84697".equals(id)
1434: || "Variables__84710".equals(id)) {
1435: // An error. See 11.4
1436: // but are processors allowed to recover?
1437: // Hmm according to section 17, the
1438: // processor must signal these errors
1439: // and may but need not recover from them.
1440: // Xalan recovers. Microsoft doesn't.
1441: } else if ("Output__78176".equals(id)) {
1442: // I think the test case is wrong; I see
1443: // nothing in the spec that says this is
1444: // an error.
1445: } else if (id.startsWith("XSLTFunctions__100")) {
1446: // I think these test cases are all wrong
1447: // except perhaps XSLTFunctions__10026; I
1448: // see nothing in the spec that says this
1449: // is an error. These are all about the
1450: // unparsed-entity-uri function.
1451: } else if ("Namespace__78027".equals(id)) {
1452: // Test case is incorrect. This should
1453: // operate in forwards compatible mode.
1454: // Xalan gets this right.
1455: } else if ("Output_Output_UseStandAloneAttributeWithMultipleRoots"
1456: .equals(id)) {
1457: // Error only appears when document is serialized;
1458: // not before
1459: } else { // transform should have failed
1460: fail("Transformed " + style + "\n id: "
1461: + testcase.getAttributeValue("id"));
1462: }
1463: } else {
1464: try {
1465: if ("Attributes_xsl_attribute_dup_attr_with_namespace_conflict"
1466: .equals(id)
1467: || "BVTs_bvt057".equals(id)) {
1468: // This test case requires namespace prefix rewriting,
1469: // so the output won't be exactly the same between processors
1470: continue;
1471: } else if ("Comment_DisableOutputEscaping_XslTextInXslComment"
1472: .equals(id)) {
1473: // Test case output is wrong
1474: continue;
1475: } else if ("Output__77927".equals(id)
1476: || "Output__77928".equals(id)
1477: || "Output__84304".equals(id)
1478: || "Output__84305".equals(id)
1479: || "Output__84312".equals(id)
1480: || "Output__84619".equals(id)
1481: || "Output__84620".equals(id)
1482: || "Output_EntityRefInAttribHtml"
1483: .equals(id)) {
1484: // These test cases have incorrect line
1485: // breaks in the reference output.
1486: continue;
1487: } else if ("Output_Modified84433"
1488: .equals(id)) {
1489: // This test case uses disable output escaping
1490: // so the results don't match up
1491: continue;
1492: } else if ("Sorting_Sort_SortTextWithNonTextCharacters"
1493: .equals(id)) {
1494: // Xalan and MSXML don't sort non alphabetic characters
1495: // exactly the same, but that's legal
1496: continue;
1497: } else if ("Text_DoeWithCdataInText"
1498: .equals(id)) {
1499: // Requires disable-output-escaping
1500: continue;
1501: } else if ("Whitespaces__91443".equals(id)
1502: || "Whitespaces__91444".equals(id)) {
1503: // Xalan bug
1504: // See http://issues.apache.org/jira/browse/XALANJ-1969
1505: continue;
1506: } else if ("AVTs__77591".equals(id)) {
1507: // test suite bug; doesn't escape tabs in output. See
1508: // http://lists.oasis-open.org/archives/xslt-conformance-comment/200409/msg00017.html
1509: } else if ("Keys_MultipltKeysInclude"
1510: .equals(id)) {
1511: // Xalan bug
1512: // http://issues.apache.org/jira/browse/XALANJ-1956
1513: }
1514: /* else if ("Keys_PerfRepro3".equals(id) ) {
1515: // Suspected Xalan bug
1516: // http://issues.apache.org/jira/browse/XALANJ-1955
1517: } */
1518: else if ("Number__84683".equals(id)) {
1519: // test suite bug
1520: } else if ("Number__84687".equals(id)) {
1521: // test suite bug
1522: } else if ("Number__84692".equals(id)) {
1523: // test suite bug
1524: } else if ("Number__84694".equals(id)) {
1525: // Test suite expects Roman number for zero
1526: // to be the empty string while Xalan uses 0
1527: } else if ("Number__84699".equals(id)) {
1528: // Xalan bug
1529: } else if ("Number__84700".equals(id)) {
1530: // Xalan bug; extra whitespace. Possibly
1531: // the same as
1532: } else if ("Number__84716".equals(id)) {
1533: // Xalan doesn't support Russian
1534: // number formatting
1535: } else if ("Number__84717".equals(id)) {
1536: // Xalan supports more Japanese than the
1537: // test case does
1538: } else if ("Number__84722".equals(id)
1539: || "Number__84723".equals(id)
1540: || "Number__84724".equals(id)
1541: || "Number__84725".equals(id)) {
1542: // Acceptable locale support differences
1543: } else if ("Number_NaNOrInvalidValue"
1544: .equals(id)) {
1545: // Double bug! Test case is wrong and
1546: // Xalan gets this wrong!
1547: } else if ("Number_ValueAsNodesetTest1"
1548: .equals(id)
1549: || "Number_ValueAsEmptyNodeset"
1550: .equals(id)) {
1551: // Another double bug! Test case is wrong and
1552: // Xalan gets this wrong!
1553: } else if (id
1554: .equals("XSLTFunctions_BooleanFunction")) {
1555: // I think the test case is wrong; or perhaps unspecified
1556: } else if (id
1557: .equals("XSLTFunctions_TestIdFuncInComplexStruct")) {
1558: // I think the Xalan output white space is wrong;
1559: // http://issues.apache.org/jira/browse/XALANJ-1947
1560: } else if (id
1561: .equals("XSLTFunctions__testOn-0.00")) {
1562: // Possible test suite bug. See
1563: // http://issues.apache.org/jira/browse/XALANJ-2226
1564: } else {
1565: Document expectedResult;
1566: if (strip)
1567: expectedResult = strippingBuilder
1568: .build(output);
1569: else
1570: expectedResult = builder
1571: .build(output);
1572: Document actualResult = XSLTransform
1573: .toDocument(result);
1574: assertEquals("Mismatch with " + id,
1575: expectedResult, actualResult);
1576: }
1577: } // end try
1578: catch (ParsingException ex) {
1579: // a few of the test cases generate
1580: // text or HTML output rather than
1581: // well-formed XML. For the moment, I
1582: // just skip these.
1583: continue;
1584: } catch (IllegalAddException ex) {
1585: // A few of the test cases generate
1586: // incomplete documents so we can't
1587: // compare output. Perhaps I could
1588: // wrap in an element, then get children
1589: // to build a Node object rather than a
1590: // Document???? i.e. a fragment parser?
1591: // Could use a SequenceInputStream to hack this
1592: }
1593: } // end else
1594:
1595: } // end try
1596: catch (MalformedURIException ex) {
1597:
1598: } catch (FileNotFoundException ex) {
1599: // The catalog doesn't always match what's on disk
1600: } catch (UnknownHostException ex) {
1601: // A few tests like ProcessingInstruction__78197
1602: // point to external DTD subsets that can't be loaded
1603: } catch (ParsingException ex) {
1604: // several stylesheets use relative namespace URIs XOM
1605: // does not support; skip the test
1606: if (ex.getCause() instanceof MalformedURIException) {
1607: continue;
1608: }
1609:
1610: String operation = scenario
1611: .getAttributeValue("operation");
1612: if (!"execution-error".equals(operation)) {
1613: if ("Namespace_XPath_PredefinedPrefix_XML"
1614: .equals(id)) {
1615: // uses relative namespace URIs
1616: } else if ("Sorting__78191".equals(id)
1617: || "Text__78245".equals(id)
1618: || "Text__78273".equals(id)
1619: || "Text__78281".equals(id)) {
1620: // binds XML namespace to prefix other than xml
1621: } else {
1622: System.err.println(id + ": "
1623: + ex.getMessage());
1624: throw ex;
1625: }
1626: }
1627: } catch (XSLException ex) {
1628: // If the output was null the transformation
1629: // was expected to fail
1630: if (output != null) {
1631: Throwable cause = ex.getCause();
1632: if ("Attributes__81487".equals(id)
1633: || "Attributes__81551".equals(id)) {
1634: // spec inconsistency; see
1635: // http://lists.w3.org/Archives/Public/xsl-editors/2004JulSep/0003.html
1636: continue;
1637: } else if (cause instanceof MissingResourceException) {
1638: // Xalan bug;
1639: // http://issues.apache.org/jira/secure/ManageAttachments.jspa?id=27366
1640: } else if ("Include_Include_IncludedStylesheetShouldHaveDifferentBaseUri"
1641: .equals(id)) {
1642: // This test case is wrong; Uses backslash in URI
1643: } else if ("Elements__89070".equals(id)) {
1644: // bug fixed in later versions of Xalan
1645: } else if ("Namespace-alias_Namespace-Alias_NSAliasForDefaultWithExcludeResPref"
1646: .equals(id)) {
1647: // This test case is wrong; it uses a backslash in a URI
1648: } else if ("Variables_VariableWithinVariable"
1649: .equals(id)) {
1650: // Xalan does not recover from this one
1651: } else if ("BVTs_bvt054".equals(id)) {
1652: // Xalan bug
1653: // http://issues.apache.org/jira/browse/XALANJ-1952
1654: continue;
1655: } else if ("BVTs_bvt094".equals(id)) {
1656: // Xalan bug
1657: // http://issues.apache.org/jira/browse/XALANJ-1953
1658: continue;
1659: } else if ("Output__78177".equals(id)
1660: || "Output__84009".equals(id)) {
1661: // Xalan does not recover from this error
1662: // which involves duplicate and possibly conflicting xsl:output elements
1663: continue;
1664: } else if ("Comment_Comment_CDATAWithSingleHyphen"
1665: .equals(id)
1666: || "Comment_Comment_DoubleHypenEntitywithDelCharacter"
1667: .equals(id)
1668: || "Comment_Comment_LineOfAllHyphens"
1669: .equals(id)
1670: || "Comment_Comment_SingleHyphenOnly"
1671: .equals(id)
1672: || "Comment_Comment_DoubleHyphenONLY"
1673: .equals(id)) {
1674: // Begins comment data with hyphen, which XOM doesn't allow
1675: continue;
1676: } else if ("ProcessingInstruction_ValueOfandTextWithDoeInProcInstr"
1677: .equals(id)) {
1678: // Begins processing instruction data with white space, which XOM doesn't allow
1679: continue;
1680: } else if ("Elements__89716".equals(id)
1681: || "Elements__89717".equals(id)
1682: || "Elements__89718".equals(id)
1683: || "Output__84309".equals(id)
1684: || "Namespace__77670".equals(id)) {
1685: // Xalan doesn't recover from these, though recovery is allowed
1686: continue;
1687: } else if ("Output__84306".equals(id)) {
1688: // Xalan bug
1689: // http://issues.apache.org/jira/browse/XALANJ-1954
1690: continue;
1691: } else if ("Output__84014".equals(id)) {
1692: // Fixed in later version of Xalan than is bundled with JDK
1693: continue;
1694: } else if (cause instanceof MalformedURIException) {
1695: // Some of the tests generate relative namespace URIs
1696: // XOM doesn't support
1697: continue;
1698: } else {
1699: System.out.println(id + ": "
1700: + ex.getMessage());
1701: System.out.println("in " + style);
1702: if (cause != null) {
1703: System.out.println("cause: "
1704: + cause.getMessage());
1705: }
1706: throw ex;
1707: }
1708: }
1709: } // end catch
1710: catch (XMLException ex) {
1711: if ("Text_modified78309".equals(id)) {
1712: // output is not a full document
1713: } else {
1714: System.err.println(id);
1715: throw ex;
1716: }
1717: }
1718:
1719: } // end for
1720:
1721: } // end if
1722:
1723: }
1724:
1725: public void testKeysPerfRepro3() throws IOException,
1726: ParsingException, XSLException {
1727:
1728: Builder builder = new Builder();
1729: NodeFactory stripper = new StrippingFactory();
1730: File base = new File("data");
1731: base = new File(base, "oasis-xslt-testsuite");
1732: base = new File(base, "TESTS");
1733:
1734: File input = new File(base,
1735: "MSFT_CONFORMANCE_TESTS/KEYS/input.xml");
1736: File style = new File(base,
1737: "MSFT_CONFORMANCE_TESTS/KEYS/input.xsl");
1738: File output = new File(base,
1739: "MSFT_CONFORMANCE_TESTS/KEYS/out/PerfRepro3.txt");
1740: ;
1741:
1742: Document styleDoc = builder.build(style);
1743: Document inputDoc = builder.build(input);
1744: XSLTransform xform = new XSLTransform(styleDoc);
1745: Nodes result = xform.transform(inputDoc);
1746: Document expectedResult = builder.build(output);
1747: Document actualResult = XSLTransform.toDocument(result);
1748: assertEquals(expectedResult, actualResult);
1749:
1750: }
1751:
1752: public void testSorting__89749() throws IOException,
1753: ParsingException, XSLException {
1754:
1755: Builder builder = new Builder();
1756: NodeFactory stripper = new StrippingFactory();
1757: File base = new File("data");
1758: base = new File(base, "oasis-xslt-testsuite");
1759: base = new File(base, "TESTS");
1760:
1761: File input = new File(base,
1762: "MSFT_CONFORMANCE_TESTS/Sorting/sorttest.xml");
1763: File style = new File(base,
1764: "MSFT_CONFORMANCE_TESTS/Sorting/2_5_13_repeat.xsl");
1765: File output = new File(base,
1766: "MSFT_CONFORMANCE_TESTS/Sorting/out/89749.txt");
1767: ;
1768:
1769: Document styleDoc = builder.build(style);
1770: Document inputDoc = builder.build(input);
1771: XSLTransform xform = new XSLTransform(styleDoc);
1772: Nodes result = xform.transform(inputDoc);
1773: /*Document expectedResult = builder.build(output);
1774: Document actualResult = XSLTransform.toDocument(result);
1775: assertEquals(expectedResult, actualResult); */
1776:
1777: }
1778:
1779: public void testToDocumentWithEmptyNodes() {
1780:
1781: try {
1782: XSLTransform.toDocument(new Nodes());
1783: fail("Converted empty nodes to document");
1784: } catch (XMLException success) {
1785: assertNotNull(success.getMessage());
1786: }
1787:
1788: }
1789:
1790: public void testToDocumentWithNoRoot() {
1791:
1792: Nodes input = new Nodes();
1793: input.append(new Comment("data"));
1794: try {
1795: XSLTransform.toDocument(new Nodes());
1796: fail("Converted comment to document");
1797: } catch (XMLException success) {
1798: assertNotNull(success.getMessage());
1799: }
1800:
1801: }
1802:
1803: public void testToDocumentWithText() {
1804:
1805: Nodes input = new Nodes();
1806: Element root = new Element("root");
1807: Comment comment = new Comment("data");
1808: ProcessingInstruction pi = new ProcessingInstruction("target",
1809: "data");
1810: input.append(comment);
1811: input.append(root);
1812: input.append(pi);
1813: input.append(new Text("text"));
1814: try {
1815: XSLTransform.toDocument(new Nodes());
1816: fail("Converted text to document");
1817: } catch (XMLException success) {
1818: assertNotNull(success.getMessage());
1819: }
1820:
1821: }
1822:
1823: public void testToDocumentWithAttribute() {
1824:
1825: Nodes input = new Nodes();
1826: Element root = new Element("root");
1827: Comment comment = new Comment("data");
1828: ProcessingInstruction pi = new ProcessingInstruction("target",
1829: "data");
1830: input.append(comment);
1831: input.append(root);
1832: input.append(pi);
1833: input.append(new Attribute("name", "text"));
1834: try {
1835: XSLTransform.toDocument(new Nodes());
1836: fail("Converted text to document");
1837: } catch (XMLException success) {
1838: assertNotNull(success.getMessage());
1839: }
1840:
1841: }
1842:
1843: public void testToDocumentWithDocType() {
1844:
1845: Nodes input = new Nodes();
1846: Element root = new Element("root");
1847: DocType doctype = new DocType("root");
1848: Comment comment = new Comment("data");
1849: ProcessingInstruction pi = new ProcessingInstruction("target",
1850: "data");
1851: input.append(comment);
1852: input.append(doctype);
1853: input.append(root);
1854: input.append(pi);
1855: Document output = XSLTransform.toDocument(input);
1856: assertEquals(root, output.getRootElement());
1857: assertEquals(comment, output.getChild(0));
1858: assertEquals(doctype, output.getChild(1));
1859: assertEquals(pi, output.getChild(3));
1860: assertEquals(input.size(), output.getChildCount());
1861:
1862: }
1863:
1864: public void testToDocumentWithDocTypeInEpilog() {
1865:
1866: Nodes input = new Nodes();
1867: Element root = new Element("root");
1868: DocType doctype = new DocType("root");
1869: Comment comment = new Comment("data");
1870: ProcessingInstruction pi = new ProcessingInstruction("target",
1871: "data");
1872: input.append(comment);
1873: input.append(root);
1874: input.append(doctype);
1875: input.append(pi);
1876: try {
1877: XSLTransform.toDocument(input);
1878: fail("Allowed doctype in epilog");
1879: } catch (XMLException success) {
1880: assertNotNull(success.getMessage());
1881: }
1882:
1883: }
1884:
1885: public void testToDocumentWithDoubleRoot() {
1886:
1887: Nodes input = new Nodes();
1888: Element root = new Element("root");
1889: Comment comment = new Comment("data");
1890: input.append(comment);
1891: input.append(root);
1892: input.append(new Element("root2"));
1893: try {
1894: XSLTransform.toDocument(input);
1895: fail("Allowed two root elements");
1896: } catch (XMLException success) {
1897: assertNotNull(success.getMessage());
1898: }
1899:
1900: }
1901:
1902: public void testToDocumentWithSingleRoot() {
1903:
1904: Nodes input = new Nodes();
1905: Element root = new Element("root");
1906: input.append(root);
1907: Document output = XSLTransform.toDocument(input);
1908: assertEquals(root, output.getRootElement());
1909: assertEquals(input.size(), output.getChildCount());
1910:
1911: }
1912:
1913: public void testToDocumentWithPrologAndEpilog() {
1914:
1915: Nodes input = new Nodes();
1916: Element root = new Element("root");
1917: Comment comment = new Comment("data");
1918: ProcessingInstruction pi = new ProcessingInstruction("target",
1919: "data");
1920: input.append(comment);
1921: input.append(root);
1922: input.append(pi);
1923: Document output = XSLTransform.toDocument(input);
1924: assertEquals(root, output.getRootElement());
1925: assertEquals(comment, output.getChild(0));
1926: assertEquals(pi, output.getChild(2));
1927: assertEquals(input.size(), output.getChildCount());
1928:
1929: }
1930:
1931: }
|