Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 2,005   Methods: 61
NCLOC: 1,409   Classes: 4
 
 Source file Conditionals Statements Methods TOTAL
XSLTransformTest.java 64.7% 92.9% 98.4% 87.2%
coverage coverage
 1    /* Copyright 2002-2006 Elliotte Rusty Harold
 2   
 3    This library is free software; you can redistribute it and/or modify
 4    it under the terms of version 2.1 of the GNU Lesser General Public
 5    License as published by the Free Software Foundation.
 6   
 7    This library is distributed in the hope that it will be useful,
 8    but WITHOUT ANY WARRANTY; without even the implied warranty of
 9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 10    GNU Lesser General Public License for more details.
 11   
 12    You should have received a copy of the GNU Lesser General Public
 13    License along with this library; if not, write to the
 14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 15    Boston, MA 02111-1307 USA
 16   
 17    You can contact Elliotte Rusty Harold by sending e-mail to
 18    elharo@metalab.unc.edu. Please include the word "XOM" in the
 19    subject line. The XOM home page is located at http://www.xom.nu/
 20    */
 21    package nu.xom.tests;
 22   
 23    import java.io.ByteArrayOutputStream;
 24    import java.io.File;
 25    import java.io.FileNotFoundException;
 26    import java.io.FileOutputStream;
 27    import java.io.IOException;
 28    import java.io.OutputStream;
 29    import java.io.PrintStream;
 30    import java.net.UnknownHostException;
 31    import java.util.MissingResourceException;
 32   
 33    import nu.xom.Attribute;
 34    import nu.xom.Builder;
 35    import nu.xom.Comment;
 36    import nu.xom.DocType;
 37    import nu.xom.Document;
 38    import nu.xom.Element;
 39    import nu.xom.Elements;
 40    import nu.xom.IllegalAddException;
 41    import nu.xom.MalformedURIException;
 42    import nu.xom.Namespace;
 43    import nu.xom.Node;
 44    import nu.xom.NodeFactory;
 45    import nu.xom.Nodes;
 46    import nu.xom.ParentNode;
 47    import nu.xom.ParsingException;
 48    import nu.xom.ProcessingInstruction;
 49    import nu.xom.Serializer;
 50    import nu.xom.Text;
 51    import nu.xom.XMLException;
 52    import nu.xom.xslt.XSLException;
 53    import nu.xom.xslt.XSLTransform;
 54   
 55    /**
 56    * <p>
 57    * Unit tests for the XSLT engine.
 58    * </p>
 59    *
 60    * <p>
 61    * Many of the tests in this suite use an identity transformation.
 62    * This is often done to make sure I get a particular content into
 63    * the output tree in order to test the XSLTHandler.
 64    * </p>
 65    *
 66    * @author Elliotte Rusty Harold
 67    * @version 1.2d1
 68    *
 69    */
 70    public class XSLTransformTest extends XOMTestCase {
 71   
 72   
 73  50 public XSLTransformTest(String name) {
 74  50 super(name);
 75    }
 76   
 77   
 78    // Not a literal result element as stylesheet
 79    // because it's missing the xsl:version attribute
 80    private String notAStyleSheet =
 81    "<?xml-stylesheet href=\"file.css\" type=\"text/css\"?>"
 82    + "<!-- test -->"
 83    + "<test xmlns:xlink='http://www.w3.org/TR/1999/xlink'>Hello dear"
 84    + "\r\n<em id=\"p1\" xmlns:none=\"http://www.example.com\">"
 85    + "very important</em>"
 86    + "<span xlink:type='simple'>here&apos;s the link</span>\r\n"
 87    + "<svg:svg xmlns:svg='http://www.w3.org/TR/2000/svg'>"
 88    + "<svg:text>text in a namespace</svg:text></svg:svg>\r\n"
 89    + "<svg xmlns='http://www.w3.org/TR/2000/svg'>"
 90    + "<text>text in a namespace</text></svg>"
 91    + "</test>\r\n"
 92    + "<!--epilog-->";
 93   
 94   
 95    // This class tests a lot of error conditions, which
 96    // Xalan annoyingly logs to System.err. This hides System.err
 97    // before each test and restores it after each test.
 98    private PrintStream systemErr = System.err;
 99   
 100    private File inputDir;
 101   
 102  50 protected void setUp() {
 103   
 104  50 System.setErr(new PrintStream(new ByteArrayOutputStream()));
 105   
 106  50 inputDir = new File("data");
 107  50 inputDir = new File(inputDir, "xslt");
 108  50 inputDir = new File(inputDir, "input");
 109   
 110    }
 111   
 112   
 113  50 protected void tearDown() {
 114  50 System.setErr(systemErr);
 115    }
 116   
 117    // Primarily this makes sure the XSLTHandler can handle various
 118    // edge cases
 119  1 public void testIdentityTransform()
 120    throws ParsingException, IOException, XSLException {
 121   
 122  1 File stylesheet = new File(inputDir, "identity.xsl");
 123  1 Builder builder = new Builder();
 124  1 Document stylesheetDoc = builder.build(stylesheet);
 125  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 126  1 Element root = new Element("root", "http://www.example.org");
 127  1 root.appendChild(new Text("some data"));
 128  1 root.appendChild(new Element("something"));
 129  1 root.addAttribute(new Attribute("test", "test"));
 130  1 root.addAttribute(new Attribute("pre:red", "http://www.red.com/", "value"));
 131  1 Document input = new Document(root);
 132  1 Nodes output = xform.transform(input);
 133  1 assertEquals(root, output.get(0));
 134   
 135    }
 136   
 137   
 138  1 public void testPrefixMappingIssues()
 139    throws XSLException, ParsingException, IOException {
 140   
 141  1 String doc = "<test>"
 142    + "<span xmlns:a='http://www.example.com'/>"
 143    + "<span xmlns:b='http://www.example.net'/>"
 144    + "</test>";
 145  1 File stylesheet = new File(inputDir, "identity.xsl");
 146  1 Builder builder = new Builder();
 147  1 Document stylesheetDoc = builder.build(stylesheet);
 148  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 149  1 Document input = builder.build(doc, "http://example.org/");
 150  1 Nodes result = xform.transform(input);
 151  1 assertEquals(input.getRootElement(), result.get(0));
 152   
 153    }
 154   
 155   
 156  1 public void testDocumentConstructor()
 157    throws ParsingException, IOException {
 158   
 159  1 try {
 160  1 Builder builder = new Builder();
 161  1 Document doc = builder.build(notAStyleSheet,
 162    "http://www.example.com");
 163  1 new XSLTransform(doc);
 164    /*Document input = builder.build("<root />", "http://example.org/");
 165    Nodes result = xform.transform(input); */
 166  0 fail("Compiled non-stylesheet");
 167    }
 168    catch (XSLException success) {
 169  1 assertNotNull(success.getMessage());
 170    }
 171   
 172    }
 173   
 174   
 175  1 public void testLiteralResultElementUsedAsStylesheet()
 176    throws ParsingException, IOException, XSLException {
 177   
 178  1 String literalResultElementAsStylesheet =
 179    "<html xsl:version='1.0'\n"
 180    + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\n"
 181    + " xmlns='http://www.w3.org/TR/xhtml1/strict'>\n"
 182    + " <head>\n"
 183    + " <title>Expense Report Summary</title>\n"
 184    + " </head>\n"
 185    + " <body>\n"
 186    + " <p>Total Amount: <xsl:value-of select='expense-report/total'/></p>\n"
 187    + " </body>\n"
 188    + "</html>\n";
 189   
 190  1 Builder builder = new Builder();
 191  1 Document stylesheet = builder.build(literalResultElementAsStylesheet,
 192    "http://www.example.com");
 193  1 XSLTransform transform = new XSLTransform(stylesheet);
 194  1 Document doc = builder.build(notAStyleSheet,
 195    "http://www.example.com");
 196  1 Nodes result = transform.transform(doc);
 197  1 Element root = (Element) (result.get(0));
 198  1 assertEquals("html", root.getQualifiedName());
 199  1 assertEquals(2, root.getChildCount());
 200   
 201    }
 202   
 203   
 204    /* <xsl:template match="/">
 205    <element1>some data and <content/> for a test</element1>
 206    <element2>Remember, the XSLT processor is going to strip out the literal white space</element2>
 207    <element3>some data and <content/> for a <!--test--></element3>
 208    <element4/>
 209    <xsl:comment>test</xsl:comment>
 210    <xsl:processing-instruction name="test">PIs are not treated as literals in XSLT?</xsl:processing-instruction>
 211    </xsl:template> */
 212   
 213  1 public void testCreateDocumentFragment()
 214    throws ParsingException, IOException, XSLException {
 215   
 216  1 Element element1 = new Element("element1");
 217  1 element1.appendChild("some data and ");
 218  1 element1.appendChild(new Element("content"));
 219  1 element1.appendChild(" for a test");
 220   
 221  1 Element element2 = new Element("element2");
 222  1 element2.appendChild(
 223    "Remember, the XSLT processor is going to strip out the literal white space"
 224    );
 225  1 File doc = new File(inputDir, "8-14.xml");
 226  1 File stylesheet = new File(inputDir, "fragment.xsl");
 227  1 Builder builder = new Builder();
 228  1 Document stylesheetDoc = builder.build(stylesheet);
 229  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 230  1 Document input = builder.build(doc);
 231  1 Nodes output = xform.transform(input);
 232  1 assertEquals(6, output.size());
 233  1 assertEquals(element1, output.get(0));
 234  1 assertEquals(element2, output.get(1));
 235  1 assertEquals(new Element("element4"), output.get(3));
 236  1 assertEquals(new Comment("test"), output.get(4));
 237  1 assertEquals(new ProcessingInstruction("test",
 238    "PIs are not treated as literals in XSLT?"), output.get(5));
 239   
 240    }
 241   
 242   
 243  1 public void testTransform()
 244    throws ParsingException, IOException, XSLException {
 245   
 246  1 File doc = new File(inputDir, "8-1.xml");
 247  1 File stylesheet = new File(inputDir, "8-8.xsl");
 248  1 Builder builder = new Builder();
 249  1 Document stylesheetDoc = builder.build(stylesheet);
 250  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 251  1 Nodes output = xform.transform(builder.build(doc));
 252  1 assertEquals(1, output.size());
 253  1 Document result = new Document((Element) (output.get(0)));
 254   
 255  1 Document expected = builder.build("data/xslt/output/8-8.xml");
 256  1 assertEquals(expected, result);
 257   
 258    }
 259   
 260   
 261  1 public void testSetParameter()
 262    throws ParsingException, IOException, XSLException {
 263   
 264  1 File doc = new File(inputDir, "8-1.xml");
 265  1 File stylesheet = new File(inputDir, "paramtest.xsl");
 266  1 Builder builder = new Builder();
 267  1 Document stylesheetDoc = builder.build(stylesheet);
 268  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 269  1 xform.setParameter("test", new Double(2));
 270  1 Nodes output = xform.transform(builder.build(doc));
 271  1 assertEquals(1, output.size());
 272  1 Element result = (Element) output.get(0);
 273  1 assertEquals("<root>2</root>", result.toXML());
 274   
 275    }
 276   
 277   
 278  1 public void testSetParameterWithNamespace()
 279    throws ParsingException, IOException, XSLException {
 280   
 281  1 File doc = new File(inputDir, "8-1.xml");
 282  1 File stylesheet = new File(inputDir, "namespaceparamtest.xsl");
 283  1 Builder builder = new Builder();
 284  1 Document stylesheetDoc = builder.build(stylesheet);
 285  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 286  1 xform.setParameter("test", "http://www.xom.nu/", new Double(2));
 287  1 Nodes output = xform.transform(builder.build(doc));
 288  1 assertEquals(1, output.size());
 289  1 Element result = (Element) output.get(0);
 290  1 assertEquals("<root xmlns:pre=\"http://www.xom.nu/\">2</root>",
 291    result.toXML());
 292   
 293    }
 294   
 295   
 296  1 public void testRemoveParameterWithNamespace()
 297    throws ParsingException, IOException, XSLException {
 298   
 299  1 File doc = new File(inputDir, "8-1.xml");
 300  1 File stylesheet = new File(inputDir, "namespaceparamtest.xsl");
 301  1 Builder builder = new Builder();
 302  1 Document stylesheetDoc = builder.build(stylesheet);
 303  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 304  1 xform.setParameter("test", "http://www.xom.nu/", new Double(2));
 305  1 xform.setParameter("test", "http://www.xom.nu/", null);
 306  1 Nodes output = xform.transform(builder.build(doc));
 307  1 assertEquals(1, output.size());
 308  1 Element result = (Element) output.get(0);
 309  1 assertEquals("<root xmlns:pre=\"http://www.xom.nu/\">1</root>",
 310    result.toXML());
 311   
 312    }
 313   
 314   
 315  1 public void testRemoveParameter()
 316    throws ParsingException, IOException, XSLException {
 317   
 318  1 File doc = new File(inputDir, "8-1.xml");
 319  1 File stylesheet = new File(inputDir, "paramtest.xsl");
 320  1 Builder builder = new Builder();
 321  1 Document stylesheetDoc = builder.build(stylesheet);
 322  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 323  1 xform.setParameter("test", new Double(2));
 324  1 xform.setParameter("test", null);
 325  1 Nodes output = xform.transform(builder.build(doc));
 326  1 assertEquals(1, output.size());
 327  1 Element result = (Element) output.get(0);
 328  1 assertEquals("<root>1</root>", result.toXML());
 329   
 330    }
 331   
 332   
 333  1 public void testTransformWithCFilter()
 334    throws ParsingException, IOException, XSLException {
 335   
 336  1 File doc = new File(inputDir, "8-1.xml");
 337  1 File stylesheet = new File(inputDir, "8-8.xsl");
 338  1 Builder builder = new Builder();
 339  1 Document stylesheetDoc = builder.build(stylesheet);
 340  1 XSLTransform xform = new XSLTransform(
 341    stylesheetDoc, new NodeFactoryTest.CFactory());
 342   
 343  1 Nodes output = xform.transform(builder.build(doc));
 344  1 assertEquals(1, output.size());
 345  1 Document result = new Document((Element) (output.get(0)));
 346   
 347  1 Document expected = builder.build("data/xslt/output/8-8c.xml");
 348  1 assertEquals(expected, result);
 349   
 350    }
 351   
 352   
 353  1 public void testCreateDocumentFragmentWithCommentFilter()
 354    throws ParsingException, IOException, XSLException {
 355   
 356  1 Element element1 = new Element("element1");
 357  1 element1.appendChild("some data and ");
 358  1 element1.appendChild(new Element("content"));
 359  1 element1.appendChild(" for a test");
 360   
 361  1 Element element2 = new Element("element2");
 362  1 element2.appendChild(
 363    "Remember, the XSLT processor is going to strip out the literal white space"
 364    );
 365  1 File doc = new File(inputDir, "8-14.xml");
 366  1 File stylesheet = new File(inputDir, "fragment.xsl");
 367  1 Builder builder = new Builder();
 368  1 Document stylesheetDoc = builder.build(stylesheet);
 369  1 XSLTransform xform = new XSLTransform(
 370    stylesheetDoc, new NodeFactoryTest.CommentFilter());
 371   
 372  1 Document input = builder.build(doc);
 373  1 Nodes output = xform.transform(input);
 374  1 assertEquals(5, output.size());
 375  1 assertEquals(element1, output.get(0));
 376  1 assertEquals(element2, output.get(1));
 377  1 assertEquals(new Element("element4"), output.get(3));
 378  1 assertEquals(new ProcessingInstruction("test",
 379    "PIs are not treated as literals in XSLT?"), output.get(4));
 380   
 381    }
 382   
 383   
 384  1 public void testCreateDocumentFragmentWithProcessingInstructionFilter()
 385    throws ParsingException, IOException, XSLException {
 386   
 387  1 Element element1 = new Element("element1");
 388  1 element1.appendChild("some data and ");
 389  1 element1.appendChild(new Element("content"));
 390  1 element1.appendChild(" for a test");
 391   
 392  1 Element element2 = new Element("element2");
 393  1 element2.appendChild(
 394    "Remember, the XSLT processor is going to strip out the literal white space"
 395    );
 396  1 File doc = new File(inputDir, "8-14.xml");
 397  1 File stylesheet = new File(inputDir, "fragment.xsl");
 398  1 Builder builder = new Builder();
 399  1 Document stylesheetDoc = builder.build(stylesheet);
 400  1 XSLTransform xform = new XSLTransform(stylesheetDoc,
 401    new NodeFactoryTest.ProcessingInstructionFilter());
 402   
 403  1 Document input = builder.build(doc);
 404  1 Nodes output = xform.transform(input);
 405  1 assertEquals(5, output.size());
 406  1 assertEquals(element1, output.get(0));
 407  1 assertEquals(element2, output.get(1));
 408  1 assertEquals(new Element("element4"), output.get(3));
 409  1 assertEquals(new Comment("test"), output.get(4));
 410   
 411    }
 412   
 413   
 414  1 public void testCreateDocumentFragmentWithUncommentFilter()
 415    throws ParsingException, IOException, XSLException {
 416   
 417  1 Element element1 = new Element("element1");
 418  1 element1.appendChild("some data and ");
 419  1 element1.appendChild(new Element("content"));
 420  1 element1.appendChild(" for a test");
 421   
 422  1 Element element2 = new Element("element2");
 423  1 element2.appendChild(
 424    "Remember, the XSLT processor is going to strip out the literal white space"
 425    );
 426  1 File doc = new File(inputDir, "8-14.xml");
 427  1 File stylesheet = new File(inputDir, "fragment.xsl");
 428  1 Builder builder = new Builder();
 429  1 Document stylesheetDoc = builder.build(stylesheet);
 430  1 XSLTransform xform = new XSLTransform(stylesheetDoc,
 431    new NodeFactoryTest.UncommentFilter());
 432   
 433  1 Document input = builder.build(doc);
 434  1 Nodes output = xform.transform(input);
 435  1 assertEquals(6, output.size());
 436  1 assertEquals(element1, output.get(0));
 437  1 assertEquals(element2, output.get(1));
 438  1 assertEquals(new Element("element4"), output.get(3));
 439  1 assertEquals(new Text("test"), output.get(4));
 440  1 assertEquals(new ProcessingInstruction("test",
 441    "PIs are not treated as literals in XSLT?"), output.get(5));
 442   
 443    }
 444   
 445   
 446  1 public void testTransform2()
 447    throws ParsingException, IOException, XSLException {
 448   
 449  1 File doc = new File(inputDir, "8-1.xml");
 450  1 File stylesheet = new File(inputDir, "8-12.xsl");
 451  1 Builder builder = new Builder();
 452  1 Document stylesheetDoc = builder.build(stylesheet);
 453  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 454  1 Nodes output = xform.transform(builder.build(doc));
 455  1 assertEquals(1, output.size());
 456  1 Document result = new Document((Element) (output.get(0)));
 457   
 458  1 Document expected = builder.build("data/xslt/output/8-12.xml");
 459  1 assertEquals(expected, result);
 460   
 461    }
 462   
 463   
 464   
 465    // For debugging
 466  0 private static void dumpResult(Document result, String filename)
 467    throws IOException {
 468   
 469  0 File debug = new File("data");
 470  0 debug = new File(debug, "xslt");
 471  0 debug = new File(debug, "debug/" + filename);
 472  0 OutputStream out = new FileOutputStream(debug);
 473  0 Serializer serializer = new Serializer(out);
 474  0 serializer.write(result);
 475  0 serializer.flush();
 476  0 out.close();
 477   
 478    }
 479   
 480   
 481  1 public void testTransformFromDocument()
 482    throws ParsingException, IOException, XSLException {
 483   
 484  1 File doc = new File(inputDir, "8-1.xml");
 485  1 Builder builder = new Builder();
 486  1 Document stylesheet = builder.build("data/xslt/input/8-12.xsl");
 487  1 XSLTransform xform = new XSLTransform(stylesheet);
 488  1 Nodes output = xform.transform(builder.build(doc));
 489  1 assertEquals(1, output.size());
 490  1 Document result = new Document((Element) (output.get(0)));
 491   
 492  1 Document expected = builder.build("data/xslt/output/8-12.xml");
 493  1 assertEquals(expected, result);
 494   
 495    }
 496   
 497   
 498  1 public void testTransformFromSystemID()
 499    throws ParsingException, IOException, XSLException {
 500   
 501  1 File doc = new File(inputDir, "8-1.xml");
 502  1 Builder builder = new Builder();
 503  1 String stylesheet = "data/xslt/input/8-12.xsl";
 504  1 Document stylesheetDoc = builder.build(stylesheet);
 505  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 506  1 Nodes output = xform.transform(builder.build(doc));
 507  1 assertEquals(1, output.size());
 508  1 Document result = new Document((Element) (output.get(0)));
 509   
 510  1 Document expected = builder.build("data/xslt/output/8-12.xml");
 511  1 assertEquals(expected, result);
 512   
 513    }
 514   
 515   
 516  1 public void testTransformWithNamespaces()
 517    throws ParsingException, IOException, XSLException {
 518   
 519  1 File doc = new File(inputDir, "8-14.xml");
 520  1 File stylesheet = new File(inputDir, "8-15.xsl");
 521  1 Builder builder = new Builder();
 522  1 Document stylesheetDoc = builder.build(stylesheet);
 523  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 524  1 Document input = builder.build(doc);
 525  1 Nodes output = xform.transform(input);
 526  1 assertEquals(1, output.size());
 527  1 Document result = new Document((Element) (output.get(0)));
 528   
 529  1 Document expected = builder.build("data/xslt/output/8-15.xml");
 530  1 assertEquals(expected, result);
 531   
 532    }
 533   
 534   
 535  1 public void testSingleTextNode()
 536    throws ParsingException, IOException, XSLException {
 537   
 538  1 File doc = new File(inputDir, "8-14.xml");
 539  1 File stylesheet = new File(inputDir, "singlestring.xsl");
 540  1 Builder builder = new Builder();
 541  1 Document stylesheetDoc = builder.build(stylesheet);
 542  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 543  1 Document input = builder.build(doc);
 544  1 Nodes output = xform.transform(input);
 545  1 assertEquals(1, output.size());
 546  1 Text data = (Text) (output.get(0));
 547  1 assertEquals("Data", data.getValue());
 548   
 549    }
 550   
 551   
 552  1 public void testToString()
 553    throws XSLException, ParsingException, IOException {
 554   
 555  1 File stylesheet = new File(inputDir, "singlestring.xsl");
 556  1 Builder builder = new Builder();
 557  1 Document stylesheetDoc = builder.build(stylesheet);
 558  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 559  1 assertTrue(xform.toString().startsWith("[nu.xom.xslt.XSLTransform: "));
 560   
 561    }
 562   
 563   
 564    // Make sure that method="text" doesn't affect what we get
 565    // since this is not a serialized transform
 566    // See http://issues.apache.org/bugzilla/show_bug.cgi?id=30197
 567  1 public void testTextMethod()
 568    throws ParsingException, IOException, XSLException {
 569   
 570  1 File doc = new File(inputDir, "8-14.xml");
 571  1 File stylesheet = new File(inputDir, "textmethod.xsl");
 572  1 Builder builder = new Builder();
 573  1 Document stylesheetDoc = builder.build(stylesheet);
 574  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 575  1 Document input = builder.build(doc);
 576  1 Nodes output = xform.transform(input);
 577  1 assertEquals(6, output.size());
 578  1 assertEquals("12345", output.get(0).getValue());
 579  1 assertEquals("67890", output.get(1).getValue());
 580  1 assertEquals("", output.get(2).getValue());
 581  1 assertEquals("0987654321", output.get(3).getValue());
 582  1 assertTrue(output.get(4) instanceof Comment);
 583  1 assertTrue(output.get(5) instanceof ProcessingInstruction);
 584   
 585    }
 586   
 587   
 588  1 public void testCommentWithParent()
 589    throws XSLException, ParsingException, IOException {
 590   
 591  1 Builder builder = new Builder();
 592  1 File stylesheet = new File(inputDir, "commentwithparent.xsl");
 593  1 Document stylesheetDoc = builder.build(stylesheet);
 594  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 595  1 Document input = new Document(new Element("root"));
 596  1 Nodes output = xform.transform(input);
 597  1 assertEquals(1, output.size());
 598  1 assertEquals("", output.get(0).getValue());
 599  1 Element root = (Element) output.get(0);
 600  1 assertEquals(1, root.getChildCount());
 601  1 Comment child = (Comment) root.getChild(0);
 602  1 assertEquals("test", child.getValue());
 603   
 604    }
 605   
 606   
 607  1 public void testProcessingInstructionWithParent()
 608    throws XSLException, ParsingException, IOException {
 609   
 610  1 Builder builder = new Builder();
 611  1 File stylesheet = new File(inputDir, "piwithparent.xsl");
 612  1 Document stylesheetDoc = builder.build(stylesheet);
 613  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 614  1 Document input = new Document(new Element("root"));
 615  1 Nodes output = xform.transform(input);
 616  1 assertEquals(1, output.size());
 617  1 assertEquals("", output.get(0).getValue());
 618  1 Element root = (Element) output.get(0);
 619  1 assertEquals(1, root.getChildCount());
 620  1 ProcessingInstruction child = (ProcessingInstruction) root.getChild(0);
 621  1 assertEquals("target", child.getTarget());
 622  1 assertEquals("test", child.getValue());
 623   
 624    }
 625   
 626   
 627  1 public void testTransformNodes()
 628    throws XSLException, ParsingException, IOException {
 629   
 630  1 File stylesheet = new File(inputDir, "piwithparent.xsl");
 631  1 Builder builder = new Builder();
 632  1 Nodes input = new Nodes(new Element("root"));
 633  1 Document stylesheetDoc = builder.build(stylesheet);
 634  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 635  1 Nodes output = xform.transform(input);
 636  1 assertEquals(1, output.size());
 637  1 assertEquals("", output.get(0).getValue());
 638  1 Element root = (Element) output.get(0);
 639  1 assertEquals(1, root.getChildCount());
 640  1 ProcessingInstruction child = (ProcessingInstruction) root.getChild(0);
 641  1 assertEquals("target", child.getTarget());
 642  1 assertEquals("test", child.getValue());
 643   
 644    }
 645   
 646   
 647  1 public void testCopyXMLBaseAttribute()
 648    throws XSLException, ParsingException, IOException {
 649   
 650  1 File stylesheet = new File(inputDir, "id_transform.xsl");
 651  1 Builder builder = new Builder();
 652  1 Element root = new Element("root");
 653  1 root.addAttribute(new Attribute("xml:base",
 654    Namespace.XML_NAMESPACE, "http://www.example.org/"));
 655  1 Document input = new Document(root);
 656  1 Document stylesheetDoc = builder.build(stylesheet);
 657  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 658  1 Nodes output = xform.transform(input);
 659  1 assertEquals(1, output.size());
 660  1 assertEquals("", output.get(0).getValue());
 661  1 Element rootOut = (Element) output.get(0);
 662  1 assertEquals(0, rootOut.getChildCount());
 663  1 assertEquals(1, rootOut.getAttributeCount());
 664  1 assertEquals("http://www.example.org/", rootOut.getBaseURI());
 665   
 666    }
 667   
 668   
 669  1 public void testCopyXMLLangAttribute()
 670    throws XSLException, ParsingException, IOException {
 671   
 672  1 File stylesheet = new File(inputDir, "id_transform.xsl");
 673  1 Builder builder = new Builder();
 674  1 Element root = new Element("root");
 675  1 root.addAttribute(new Attribute("xml:lang",
 676    Namespace.XML_NAMESPACE, "http://www.example.org/"));
 677  1 Document input = new Document(root);
 678  1 Document stylesheetDoc = builder.build(stylesheet);
 679  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 680  1 Nodes output = xform.transform(input);
 681  1 assertEquals(1, output.size());
 682  1 assertEquals("", output.get(0).getValue());
 683  1 Element rootOut = (Element) output.get(0);
 684  1 assertEquals(0, rootOut.getChildCount());
 685  1 assertEquals(1, rootOut.getAttributeCount());
 686   
 687    }
 688   
 689   
 690  1 public void testTriple()
 691    throws IOException, ParsingException, XSLException {
 692   
 693  1 File stylesheet = new File(inputDir, "identity.xsl");
 694  1 Builder builder = new Builder();
 695  1 Document stylesheetDoc = builder.build(stylesheet);
 696  1 XSLTransform xform = new XSLTransform(stylesheetDoc,
 697    new NodeFactoryTest.TripleElementFilter());
 698   
 699  1 String data = "<a><b><c/></b></a>";
 700  1 Document doc = builder.build(data, "http://www.example.org/");
 701   
 702  1 Nodes result = xform.transform(doc);
 703   
 704  1 assertEquals(3, result.size());
 705  1 assertEquals(result.get(0), result.get(1));
 706  1 assertEquals(result.get(1), result.get(2));
 707  1 Element a = (Element) result.get(2);
 708  1 assertEquals("a", a.getLocalName());
 709  1 assertEquals(3, a.getChildCount());
 710  1 assertEquals(0, a.getAttributeCount());
 711  1 Element b = (Element) a.getChild(1);
 712  1 assertEquals(3, b.getChildCount());
 713  1 assertEquals("b", b.getLocalName());
 714   
 715    }
 716   
 717   
 718  1 public void testPassingNullSetsDefaultFactory()
 719    throws IOException, ParsingException, XSLException {
 720   
 721  1 File stylesheet = new File(inputDir, "identity.xsl");
 722  1 Builder builder = new Builder();
 723  1 Document stylesheetDoc = builder.build(stylesheet);
 724  1 XSLTransform xform = new XSLTransform(stylesheetDoc, null);
 725   
 726  1 String data = "<a><b><c/></b></a>";
 727  1 Document doc = builder.build(data, "http://www.example.org/");
 728   
 729  1 Nodes result = xform.transform(doc);
 730   
 731  1 assertEquals(1, result.size());
 732  1 Element a = (Element) result.get(0);
 733  1 assertEquals("a", a.getLocalName());
 734  1 assertEquals(1, a.getChildCount());
 735  1 assertEquals(0, a.getAttributeCount());
 736  1 Element b = (Element) a.getChild(0);
 737  1 assertEquals(1, b.getChildCount());
 738  1 assertEquals("b", b.getLocalName());
 739   
 740    }
 741   
 742   
 743  1 public void testTransformEmptyNodesList()
 744    throws IOException, ParsingException, XSLException {
 745   
 746  1 File stylesheet = new File(inputDir, "identity.xsl");
 747  1 Builder builder = new Builder();
 748  1 Document stylesheetDoc = builder.build(stylesheet);
 749  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 750   
 751  1 Nodes result = xform.transform(new Nodes());
 752   
 753  1 assertEquals(0, result.size());
 754   
 755    }
 756   
 757   
 758  1 public void testMinimizingFactory()
 759    throws XSLException, ParsingException, IOException {
 760   
 761  1 File stylesheet = new File(inputDir, "identity.xsl");
 762  1 Builder builder = new Builder();
 763  1 Document stylesheetDoc = builder.build(stylesheet);
 764  1 XSLTransform xform = new XSLTransform(stylesheetDoc,
 765    new NodeFactoryTest.MinimizingFactory());
 766   
 767  1 Document input = builder.build("<!-- test--><test>" +
 768    "<em>data</em>\r\n<span>test</span></test>" +
 769    "<?target data?>", "http://example.org/");
 770  1 Nodes output = xform.transform(input);
 771  1 assertEquals(0, output.size());
 772   
 773    }
 774   
 775   
 776  1 public void testIllegalTransform()
 777    throws XSLException, ParsingException, IOException {
 778   
 779  1 File stylesheet = new File(inputDir, "illegaltransform.xsl");
 780  1 Builder builder = new Builder();
 781  1 Document stylesheetDoc = builder.build(stylesheet);
 782  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 783  1 Element root = new Element("root", "http://www.example.org");
 784  1 Document input = new Document(root);
 785  1 try {
 786  1 xform.transform(input);
 787  0 fail("Allowed illegal transform");
 788    }
 789    catch (XSLException ex) {
 790  1 assertNotNull(ex.getMessage());
 791    }
 792   
 793    }
 794   
 795   
 796  1 public void testRemapPrefixToSameURI()
 797    throws IOException, ParsingException, XSLException {
 798   
 799  1 File stylesheet = new File(inputDir, "identity.xsl");
 800  1 Builder builder = new Builder();
 801  1 Document stylesheetDoc = builder.build(stylesheet);
 802  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 803   
 804  1 String data = "<a xmlns:pre='http://www.example.org/'>" +
 805    "<b xmlns:pre='http://www.example.org/'>in B</b></a>";
 806  1 Document doc = builder.build(data, "http://www.example.org/");
 807   
 808  1 Nodes result = xform.transform(doc);
 809   
 810  1 assertEquals(doc.getRootElement(), result.get(0));
 811   
 812    }
 813   
 814   
 815  1 public void testElementsToAttributes()
 816    throws IOException, ParsingException, XSLException {
 817   
 818  1 File stylesheet = new File(inputDir, "identity.xsl");
 819  1 Builder builder = new Builder();
 820  1 Document stylesheetDoc = builder.build(stylesheet);
 821  1 XSLTransform xform = new XSLTransform(stylesheetDoc,
 822    new AttributeFactory());
 823   
 824  1 String data = "<a><b>in B<c>in C</c></b></a>";
 825  1 Document doc = builder.build(data, "http://www.example.org/");
 826   
 827  1 Nodes result = xform.transform(doc);
 828   
 829  1 assertEquals(1, result.size());
 830  1 Element a = (Element) result.get(0);
 831  1 assertEquals("a", a.getLocalName());
 832  1 assertEquals(0, a.getChildCount());
 833  1 assertEquals(1, a.getAttributeCount());
 834  1 assertEquals("in B", a.getAttribute("b").getValue());
 835   
 836    }
 837   
 838   
 839    private static class AttributeFactory extends NodeFactory {
 840   
 841  3 public Nodes finishMakingElement(Element element) {
 842  3 ParentNode parent = element.getParent();
 843  3 if (parent == null || parent instanceof Document) {
 844  1 return new Nodes(element);
 845    }
 846  2 return new Nodes(new Attribute(element.getQualifiedName(),
 847    element.getNamespaceURI(), element.getValue()));
 848    }
 849   
 850    }
 851   
 852   
 853  1 public void testAttributesToElements()
 854    throws IOException, ParsingException, XSLException {
 855   
 856  1 File stylesheet = new File(inputDir, "identity.xsl");
 857  1 Builder builder = new Builder();
 858  1 Document stylesheetDoc = builder.build(stylesheet);
 859  1 XSLTransform xform = new XSLTransform(stylesheetDoc,
 860    new AttributesToElements());
 861   
 862  1 String data = "<a name='value'><b x='y' a='b'/></a>";
 863  1 Document doc = builder.build(data, "http://www.example.org/");
 864   
 865  1 Nodes result = xform.transform(doc);
 866   
 867  1 assertEquals(1, result.size());
 868  1 Element a = (Element) result.get(0);
 869  1 assertEquals("a", a.getLocalName());
 870  1 assertEquals(2, a.getChildCount());
 871  1 assertEquals(0, a.getAttributeCount());
 872  1 Element name = (Element) a.getChild(0);
 873  1 assertEquals("name", name.getLocalName());
 874  1 assertEquals("value", name.getValue());
 875  1 Element b = (Element) a.getChild(1);
 876  1 assertEquals("b", b.getLocalName());
 877  1 assertEquals(2, b.getChildCount());
 878  1 assertEquals("y", b.getFirstChildElement("x").getValue());
 879  1 assertEquals("b", b.getFirstChildElement("a").getValue());
 880   
 881    }
 882   
 883   
 884    private static class AttributesToElements extends NodeFactory {
 885   
 886  3 public Nodes makeAttribute(String name, String URI,
 887    String value, Attribute.Type type) {
 888  3 Element element = new Element(name, URI);
 889  3 element.appendChild(value);
 890  3 return new Nodes(element);
 891    }
 892   
 893    }
 894   
 895   
 896  1 public void testCommentsAreTransformed()
 897    throws IOException, ParsingException, XSLException {
 898   
 899  1 File stylesheet = new File(inputDir, "identity.xsl");
 900  1 Builder builder = new Builder();
 901  1 Document stylesheetDoc = builder.build(stylesheet);
 902  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 903   
 904  1 String data = "<a><!--test--></a>";
 905  1 Document doc = builder.build(data, "http://www.example.org/");
 906   
 907  1 Nodes result = xform.transform(doc);
 908   
 909  1 assertEquals(1, result.size());
 910  1 Element a = (Element) result.get(0);
 911  1 assertEquals("a", a.getLocalName());
 912  1 assertEquals(1, a.getChildCount());
 913  1 assertEquals(0, a.getAttributeCount());
 914  1 Node child = a.getChild(0);
 915  1 assertTrue(child instanceof Comment);
 916  1 assertTrue(child.getValue().equals("test"));
 917   
 918    }
 919   
 920   
 921  1 public void testCommentToAttribute()
 922    throws IOException, ParsingException, XSLException {
 923   
 924  1 File stylesheet = new File(inputDir, "identity.xsl");
 925  1 Builder builder = new Builder();
 926  1 Document stylesheetDoc = builder.build(stylesheet);
 927  1 XSLTransform xform = new XSLTransform(stylesheetDoc,
 928    new NodeFactory() {
 929  1 public Nodes makeComment(String text) {
 930  1 return new Nodes(new Attribute("comment", text));
 931    }
 932    });
 933   
 934  1 String data = "<a><!--test--></a>";
 935  1 Document doc = builder.build(data, "http://www.example.org/");
 936   
 937  1 Nodes result = xform.transform(doc);
 938   
 939  1 assertEquals(1, result.size());
 940  1 Element a = (Element) result.get(0);
 941  1 assertEquals("a", a.getLocalName());
 942  1 assertEquals(0, a.getChildCount());
 943  1 assertEquals(1, a.getAttributeCount());
 944  1 Attribute comment = a.getAttribute(0);
 945  1 assertEquals("comment", comment.getLocalName());
 946  1 assertEquals("test", comment.getValue());
 947   
 948    }
 949   
 950   
 951  1 public void testAdditionalDefaultNamespace()
 952    throws IOException, ParsingException, XSLException {
 953   
 954  1 File stylesheet = new File(inputDir, "identity.xsl");
 955  1 Builder builder = new Builder();
 956  1 Document stylesheetDoc = builder.build(stylesheet);
 957  1 XSLTransform xform = new XSLTransform(stylesheetDoc);
 958   
 959  1 String data = "<pre:a xmlns:pre='http://www.example.org' " +
 960    "xmlns='http://www.example.net'>data</pre:a>";
 961  1 Document doc = builder.build(data, "http://www.example.org/");
 962   
 963  1 Nodes result = xform.transform(doc);
 964   
 965  1 assertEquals(1, result.size());
 966  1 Element a = (Element) result.get(0);
 967  1 assertEquals("a", a.getLocalName());
 968  1 assertEquals("pre:a", a.getQualifiedName());
 969  1 assertEquals("data", a.getValue());
 970  1 assertEquals("http://www.example.org", a.getNamespaceURI("pre"));
 971  1 assertEquals("http://www.example.net", a.getNamespaceURI(""));
 972  1 assertEquals(2, a.getNamespaceDeclarationCount());
 973   
 974    }
 975   
 976   
 977   
 978  821 private static boolean indentYes(Document styleDoc) {
 979   
 980  821 Element output = styleDoc
 981    .getRootElement()
 982    .getFirstChildElement("output",
 983    "http://www.w3.org/1999/XSL/Transform");
 984  354 if (output == null) return false;
 985   
 986  467 String indent = output.getAttributeValue("indent");
 987  467 if ("yes".equals(indent)) {
 988  283 return true;
 989    }
 990  184 else return false;
 991   
 992    }
 993   
 994   
 995    private static class StrippingFactory extends NodeFactory {
 996   
 997  1189 public Nodes makeText(String s) {
 998   
 999  1189 String stripped = stripSpace(s);
 1000  465 if (stripped.length() == 0) return new Nodes();
 1001  724 Text result = new Text(stripped);
 1002  724 return new Nodes(result);
 1003    }
 1004   
 1005  289 public Nodes makeAttribute(String name, String URI,
 1006    String value, Attribute.Type type) {
 1007  289 return new Nodes(new Attribute(name, URI, stripSpace(value), type));
 1008    }
 1009   
 1010  1478 private String stripSpace(String s) {
 1011   
 1012  1478 StringBuffer sb = new StringBuffer();
 1013  1478 for (int i = 0; i < s.length(); i++) {
 1014  25257 if (!Character.isWhitespace(s.charAt(i))) {
 1015  18566 sb.append(s.charAt(i));
 1016    }
 1017    }
 1018   
 1019  1478 return sb.toString();
 1020   
 1021    }
 1022   
 1023    }
 1024   
 1025    // XXX need to upgrade to final release of XSLT test suites
 1026    // and then split into individual tests
 1027  1 public void testOASISXalanConformanceSuite()
 1028    throws IOException, ParsingException, XSLException {
 1029   
 1030  1 Builder builder = new Builder();
 1031  1 NodeFactory stripper = new StrippingFactory();
 1032  1 Builder strippingBuilder = new Builder(stripper);
 1033   
 1034  1 File base = new File("data");
 1035  1 base = new File(base, "oasis-xslt-testsuite");
 1036  1 base = new File(base, "TESTS");
 1037  1 base = new File(base, "Xalan_Conformance_Tests");
 1038  1 File catalog = new File(base, "catalog.xml");
 1039   
 1040    // The test suite need to be installed separately. If we can't
 1041    // find the catalog, we just don't run these tests.
 1042  1 if (catalog.exists()) {
 1043  1 Document doc = builder.build(catalog);
 1044  1 Element testsuite = doc.getRootElement();
 1045  1 Elements submitters = testsuite.getChildElements("test-catalog");
 1046  1 for (int i = 0; i < submitters.size(); i++) {
 1047  1 Element submitter = submitters.get(i);
 1048  1 Elements testcases = submitter.getChildElements("test-case");
 1049  123 for (int j = 0; j < testcases.size(); j++) {
 1050   
 1051  123 Element testcase = testcases.get(j);
 1052  123 String id = testcase.getAttributeValue("id");
 1053  123 if (id.startsWith("output_")) {
 1054    // These test cases are mostly about producing
 1055    // HTML and plain text output that isn't
 1056    // relevant to XOM
 1057  0 continue;
 1058    }
 1059  123 File root = new File(base, testcase.getFirstChildElement("file-path").getValue());
 1060  123 File input = null;
 1061  123 File style = null;
 1062  123 File output = null;
 1063  123 Element scenario = testcase.getFirstChildElement("scenario");
 1064  123 Elements inputs = scenario.getChildElements("input-file");
 1065  123 for (int k = 0; k < inputs.size(); k++) {
 1066  246 Element file = inputs.get(k);
 1067  246 String role = file.getAttributeValue("role");
 1068  246 if ("principal-data".equals(role)) {
 1069  123 input = new File(root, file.getValue());
 1070    }
 1071  123 else if ("principal-stylesheet".equals(role)) {
 1072  123 style = new File(root, file.getValue());
 1073    }
 1074    }
 1075  123 Elements outputs = scenario.getChildElements("output-file");
 1076  123 for (int k = 0; k < outputs.size(); k++) {
 1077  123 Element file = outputs.get(k);
 1078  123 String role = file.getAttributeValue("role");
 1079  123 if ("principal".equals(role)) {
 1080    // Fix up OASIS catalog bugs
 1081  123 File parent = new File(root.getParent());
 1082  123 parent = new File(parent, "REF_OUT");
 1083  123 parent = new File(parent, root.getName());
 1084  123 String outputFileName = file.getValue();
 1085  123 output = new File(parent, outputFileName);
 1086    }
 1087    }
 1088   
 1089  123 try {
 1090  123 Document inputDoc = builder.build(input);
 1091  121 Document styleDoc = builder.build(style);
 1092    // If the transform specifies indent="yes".
 1093    // we remove all white space before comparing
 1094  119 XSLTransform xform;
 1095  119 if (indentYes(styleDoc)) {
 1096  5 xform = new XSLTransform(styleDoc, stripper);
 1097    }
 1098  114 else xform = new XSLTransform(styleDoc);
 1099  118 Nodes result = xform.transform(inputDoc);
 1100  117 if (output == null) {
 1101    // transform should have failed
 1102  0 fail("Transformed " + id);
 1103    }
 1104    else {
 1105  117 try {
 1106  117 Document expectedResult;
 1107  117 if (indentYes(styleDoc)) {
 1108  5 expectedResult = strippingBuilder.build(output);
 1109    }
 1110    else {
 1111  112 expectedResult = builder.build(output);
 1112    }
 1113  115 Document actualResult = XSLTransform.toDocument(result);
 1114   
 1115  112 if (id.equals("attribset_attribset40")) {
 1116    // This test does not necessarily
 1117    // produce an identical infoset due
 1118    // to necessary remapping of
 1119    // namespace prefixes.
 1120  1 continue;
 1121    }
 1122  111 else if (id.equals("axes_axes129")) {
 1123    // Xalan bug. Fixed in more recent
 1124    // version than bundled with the JDK 1.4.2_05
 1125    }
 1126  111 else if (id.equals("copy_copy56")
 1127    || id.equals("copy_copy58")
 1128    || id.equals("copy_copy60")
 1129    || id.equals("copy_copy59")) {
 1130    // Xalan bug;
 1131    // See http://issues.apache.org/jira/browse/XALANJ-1081
 1132    // Also see erratum E27 to the XSLT spec.
 1133    }
 1134  111 else if (id.equals("expression_expression02")) {
 1135    // requires unparsed entities XOM doesn't support
 1136    }
 1137  111 else if (id.equals("idkey_idkey31")) {
 1138    // Known Xalan bug
 1139    // See http://issues.apache.org/jira/browse/XALANJ-1325
 1140    }
 1141  111 else if (id.equals("idkey_idkey61")
 1142    || id.equals("idkey_idkey62")) {
 1143    // Xalan bug. Fixed in more recent
 1144    // version than bundled with the JDK 1.4.2_05
 1145    // See http://issues.apache.org/jira/browse/XALANJ-1318
 1146    }
 1147  111 else if (id.equals("impincl_impincl11")) {
 1148    // Test case bug; reported 2004-09-18
 1149    // See http://lists.oasis-open.org/archives/xslt-conformance-comment/200409/msg00001.html
 1150    }
 1151  111 else if (id.equals("math_math110")
 1152    || id.equals("math_math111")) {
 1153    // Xalan bug. Fixed in more recent
 1154    // version than bundled with the JDK 1.4.2_05
 1155    // See http://issues.apache.org/jira/browse/XALANJ-1278
 1156    }
 1157  111 else if (id.equals("numbering_numbering17")
 1158    || id.equals("numbering_numbering79")) {
 1159    // test suite bug per XSLT 1.0 erratum 24. See
 1160    // See http://issues.apache.org/jira/browse/XALANJ-1979
 1161    }
 1162  111 else if (id.equals("position_position104")) {
 1163    // Xalan bug. Fixed in more recent
 1164    // version than bundled with the JDK 1.4.2_05
 1165    }
 1166  111 else if (id.equals("position_position106")) {
 1167    // Xalan bug. Fixed in more recent
 1168    // version than bundled with the JDK 1.4.2_05
 1169    }
 1170  111 else if (id.equals("position_position107")
 1171    || id.equals("position_position109")) {
 1172    // Xalan bug. Fixed in more recent
 1173    // version than bundled with the JDK 1.4.2_05
 1174    // See http://issues.apache.org/jira/browse/XALANJ-1289
 1175    }
 1176    else {
 1177  111 assertEquals("Problem with " + id,
 1178    expectedResult, actualResult);
 1179    }
 1180    }
 1181    catch (ParsingException ex) {
 1182    // a few of the test cases generate
 1183    // text or HTML output rather than
 1184    // well-formed XML. For the moment, I
 1185    // just skip these.
 1186  2 continue;
 1187    }
 1188    catch (IllegalAddException ex) {
 1189    // A few of the test cases generate
 1190    // incomplete documents so we can't
 1191    // compare output. Perhaps I could
 1192    // wrap in an element, then get children
 1193    // to build a Nodes object rather than a
 1194    // Document???? i.e. a fragment parser?
 1195    // Could use a SequenceInputStream to hack this
 1196    }
 1197    }
 1198   
 1199    }
 1200    catch (ParsingException ex) {
 1201    // Some of the test cases contain relative
 1202    // namespace URIs XOM does not support
 1203  4 if (ex.getCause() instanceof MalformedURIException) continue;
 1204  0 throw ex;
 1205    }
 1206    catch (XSLException ex) {
 1207    // If the output was null the transformation
 1208    // was expected to fail
 1209  2 if (output != null) {
 1210    // a few of the test cases use relative namespace URIs
 1211    // XOM doesn't support
 1212  2 Throwable cause = ex.getCause();
 1213  2 if (cause instanceof MalformedURIException) {
 1214  1 continue;
 1215    }
 1216   
 1217  1 if ("impincl_impincl27".equals(id)) {
 1218    // Test case uses file: URI XOM doesn't support
 1219  0 continue;
 1220    }
 1221  1 else if ("numberformat_numberformat45".equals(id)
 1222    || "numberformat_numberformat46".equals(id)) {
 1223    // This has been fixed in Xalan 2.5.2.
 1224    // However, it's a bug in earlier versions of Xalan
 1225    // including the one bundled with the JDK 1.4.2_05
 1226    // See http://issues.apache.org/jira/browse/XALANJ-805
 1227    // XXX I think this might need an updated version of the test cases
 1228    // and expected output at this point.
 1229  0 continue;
 1230    }
 1231   
 1232  1 System.out.println(id);
 1233  1 System.out.println(ex.getMessage());
 1234  1 throw ex;
 1235    }
 1236    }
 1237   
 1238    }
 1239    }
 1240   
 1241    }
 1242   
 1243    }
 1244   
 1245  1 public void testOASISMicrosoftConformanceSuite()
 1246    throws IOException, ParsingException, XSLException {
 1247   
 1248  1 Builder builder = new Builder();
 1249  1 NodeFactory stripper = new StrippingFactory();
 1250  1 Builder strippingBuilder = new Builder(stripper);
 1251  1 File base = new File("data");
 1252  1 base = new File(base, "oasis-xslt-testsuite");
 1253  1 base = new File(base, "TESTS");
 1254  1 File catalog = new File(base, "catalog.xml");
 1255   
 1256    // The test suite need to be installed separately. If we can't
 1257    // find the catalog, we just don't run these tests.
 1258  1 if (catalog.exists()) {
 1259  1 Document doc = builder.build(catalog);
 1260  1 Element testsuite = doc.getRootElement();
 1261  1 Elements submitters = testsuite.getChildElements("test-catalog");
 1262  1 Element submitter = submitters.get(1);
 1263  1 Elements testcases = submitter.getChildElements("test-case");
 1264  702 for (int j = 0; j < testcases.size(); j++) {
 1265  702 Element testcase = testcases.get(j);
 1266  702 String id = testcase.getAttributeValue("id");
 1267  702 File root = new File(base, "MSFT_Conformance_Tests");
 1268  702 root = new File(root, testcase.getFirstChildElement("file-path").getValue());
 1269  702 File input = null;
 1270  702 File style = null;
 1271  702 File output = null;
 1272  702 Element scenario = testcase.getFirstChildElement("scenario");
 1273  702 Elements inputs = scenario.getChildElements("input-file");
 1274  702 for (int k = 0; k < inputs.size(); k++) {
 1275  1404 Element file = inputs.get(k);
 1276  1404 String role = file.getAttributeValue("role");
 1277  1404 if ("principal-data".equals(role)) {
 1278  702 input = new File(root, file.getValue());
 1279    }
 1280  702 else if ("principal-stylesheet".equals(role)) {
 1281  702 style = new File(root, file.getValue());
 1282    }
 1283    } // end for
 1284  702 Elements outputs = scenario.getChildElements("output-file");
 1285  702 for (int k = 0; k < outputs.size(); k++) {
 1286  464 Element file = outputs.get(k);
 1287  464 String role = file.getAttributeValue("role");
 1288  464 if ("principal".equals(role)) {
 1289    // Fix up OASIS catalog bugs
 1290  464 File parent = new File(root.getParent());
 1291  464 parent = new File(parent, "REF_OUT");
 1292  464 parent = new File(parent, root.getName());
 1293  464 String outputFileName = file.getValue();
 1294  464 output = new File(parent, outputFileName);
 1295    }
 1296    } // end for
 1297   
 1298  702 try {
 1299  702 Document styleDoc = builder.build(style);
 1300  585 boolean strip = indentYes(styleDoc);
 1301  585 if ("BVTs_bvt002".equals(id) || "BVTs_bvt077".equals(id)) {
 1302    // This has been fixed at least as of Xalan 2.6.0.
 1303    // However, it's a bug in earlier versions of Xalan
 1304    // including the one bundled with the JDK 1.4.2_05
 1305  2 continue;
 1306    }
 1307  583 else if ("XSLTFunctions_Bug76984".equals(id)) {
 1308    // This has been fixed at least as of Xalan 2.6.0.
 1309    // However, it's a bug in earlier versions of Xalan
 1310    // including the one bundled with the JDK 1.4.2_05
 1311  0 continue;
 1312    }
 1313  583 else if ("BVTs_bvt020".equals(id) || "BVTs_bvt022".equals(id)
 1314    || "BVTs_bvt024".equals(id) || "BVTs_bvt058".equals(id)) {
 1315    // Either a test suite bug, or a recoverable
 1316    // error Xalan doesn't recover from.
 1317  4 continue;
 1318    }
 1319  579 else if ("BVTs_bvt038".equals(id)
 1320    || "Namespace-alias__91785".equals(id)
 1321    || "Namespace-alias__91786".equals(id)) {
 1322    // a recoverable error Xalan doesn't recover from properly
 1323    // http://issues.apache.org/jira/browse/XALANJ-1957
 1324  1 continue;
 1325    }
 1326  578 else if ("Namespace_XPath_CopyNamespaceNodeToOutput".equals(id)) {
 1327    // Xalan bug
 1328    // http://issues.apache.org/jira/browse/XALANJ-1959
 1329  0 continue;
 1330    }
 1331  578 else if ("Namespace-alias_Namespace-Alias_WithinRTF".equals(id)) {
 1332    // Xalan bug
 1333    // http://issues.apache.org/jira/browse/XALANJ-1960
 1334  0 continue;
 1335    }
 1336  578 else if ("Completeness__84361".equals(id)
 1337    || "Namespace-alias__91781".equals(id)
 1338    || "Namespace-alias__91782".equals(id)
 1339    || "Namespace-alias_Namespace-Alias_Test1".equals(id)
 1340    || "Namespace-alias_Namespace-Alias_Test2".equals(id)
 1341    ) {
 1342    // a recoverable error Xalan doesn't recover from
 1343  1 continue;
 1344    }
 1345  577 else if ("Output__84008".equals(id)) {
 1346    // a recoverable error Xalan doesn't recover from
 1347  0 continue;
 1348    }
 1349  577 else if ("XSLTFunctions_ElementAvailFunctionFalseTest".equals(id)) {
 1350    // Xalan bug
 1351    // http://issues.apache.org/jira/browse/XALANJ-1961
 1352  0 continue;
 1353    }
 1354  577 else if ("XSLTFunctions_GenereateIdAppliedToNamespaceNodesOnDifferentElements".equals(id)) {
 1355    // Xalan bug
 1356    // http://issues.apache.org/jira/browse/XALANJ-1962
 1357  0 continue;
 1358    }
 1359  577 else if ("XSLTFunctions__specialCharInPattern".equals(id)) {
 1360    // a recoverable error Xalan doesn't recover from
 1361  0 continue;
 1362    }
 1363  577 else if ("XSLTFunctions_DocumentFunctionWithAbsoluteArgument".equals(id)) {
 1364    // test case bug; bad URL passed to document function
 1365  0 continue;
 1366    }
 1367  577 else if ("BVTs_bvt052".equals(id) || "Keys_PerfRepro2".equals(id)) {
 1368    // Requires a non-standard extension function
 1369  2 continue;
 1370    }
 1371  575 else if ("BVTs_bvt044".equals(id)) {
 1372    // a recoverable error Xalan doesn't recover from
 1373    // http://issues.apache.org/jira/browse/XALANJ-1957
 1374  1 continue;
 1375    }
 1376  574 else if ("BVTs_bvt039".equals(id)) {
 1377    // Xalan bug
 1378  1 continue;
 1379    }
 1380  573 else if ("BVTs_bvt033".equals(id) || "BVTs_bvt034".equals(id)) {
 1381    // Test suite bug; 2.0 is not unrecognized
 1382  2 continue;
 1383    }
 1384  571 else if ("Text__78274".equals(id) || "Text__78276".equals(id)) {
 1385    // Test suite bug; no xsl:preserve-space attribute
 1386  0 continue;
 1387    }
 1388  571 else if ("XSLTFunctions__minimumValue".equals(id)
 1389    || "XSLTFunctions__minimalValue".equals(id)) {
 1390    // test suite bug
 1391  0 continue;
 1392    }
 1393  571 else if ("Errors_err073".equals(id)) {
 1394    // Xalan bug: StackOverflowError
 1395  1 continue;
 1396    }
 1397  570 else if ("Sorting_SortExprWithCurrentInsideForEach1".equals(id)) {
 1398    // Xalan bug
 1399    // http://issues.apache.org/jira/browse/XALANJ-1970
 1400  0 continue;
 1401    }
 1402  570 else if ("BVTs_bvt041".equals(id) || "BVTs_bvt063".equals(id)
 1403    || "BVTs_bvt070".equals(id)) {
 1404    // Xalan bundled with JDK 1.4.2_05 does not recover
 1405    // from this error involving multiple conflicting
 1406    // xsl:output at same import precedence, though
 1407    // 2.6.0 does
 1408  3 continue;
 1409    }
 1410  567 Document inputDoc = builder.build(input);
 1411  381 XSLTransform xform;
 1412  124 if (strip) xform = new XSLTransform(styleDoc, stripper);
 1413  257 else xform = new XSLTransform(styleDoc);
 1414  279 Nodes result = xform.transform(inputDoc);
 1415  255 if (output == null) {
 1416  39 if ("Attributes__89463".equals(id)
 1417    || "Attributes__89465".equals(id)) {
 1418    // Processors are allowed to recover from
 1419    // this problem.
 1420  2 assertEquals(0, result.size());
 1421    }
 1422  37 else if ("Attributes__89464".equals(id)) {
 1423    // Processors are allowed to recover from
 1424    // this problem.
 1425  1 assertEquals(0, ((Element) result.get(0)).getAttributeCount());
 1426    }
 1427  36 else if ("Namespace-alias__91772".equals(id)
 1428    || "Namespace-alias__91774".equals(id)
 1429    || "Namespace-alias__91780".equals(id)
 1430    || "Namespace-alias__91790".equals(id)
 1431    || "Namespace-alias__91791".equals(id)
 1432    || "Sorting__84006".equals(id)
 1433    || "Sorting__91754".equals(id)
 1434    ) {
 1435    // Processors are allowed to recover from
 1436    // this problem.
 1437  0 continue;
 1438    }
 1439  36 else if (id.startsWith("Errors_")) {
 1440    // Processors are allowed to recover from
 1441    // most of these problems.
 1442    }
 1443  7 else if (id.startsWith("FormatNumber")) {
 1444    // Processors are allowed to recover from
 1445    // most of these problems.
 1446    }
 1447  5 else if ("BVTs_bvt074".equals(id)) {
 1448    // Processors are allowed to recover from
 1449    // this problem.
 1450  1 assertEquals(0, result.get(0).getChildCount());
 1451    }
 1452  4 else if ("XSLTFunctions__currency".equals(id)
 1453    || "XSLTFunctions__mixingInvalids".equals(id)) {
 1454    // Processors are allowed to recover from
 1455    // this problem.
 1456  0 continue;
 1457    }
 1458  4 else if ("Attributes_Attribute_UseXmlnsNsAsNamespaceForAttribute".equals(id)
 1459    || "Attributes_Attribute_UseXmlnsAsNamespaceForAttributeImplicitly".equals(id)
 1460    || "Elements_Element_UseXslElementWithNameSpaceAttrEqualToXmlnsUri".equalsIgnoreCase(id)
 1461    || "Elements_Element_UseXslElementWithNameSpaceEqualToXmlnsUri".equalsIgnoreCase(id)
 1462    ) {
 1463    // test follows namespace errata we don't accept
 1464    }
 1465  1 else if ("AttributeSets_RefToUndefinedAttributeSet".equals(id)) {
 1466    // I think the test case is wrong; I see
 1467    // nothing in the spec that says this is
 1468    // an error.
 1469    }
 1470  0 else if ("Namespace__77665".equals(id)
 1471    || "Namespace__77675".equals(id)) {
 1472    // I think the test case is wrong; I see
 1473    // nothing in the spec that says this is
 1474    // an error. See
 1475    // http://lists.oasis-open.org/archives/xslt-conformance-comment/200409/msg00007.html
 1476    }
 1477  0 else if ("Variables__84633".equals(id)
 1478    || "Variables__84634".equals(id)
 1479    || "Variables__84697".equals(id)
 1480    || "Variables__84710".equals(id)
 1481    ) {
 1482    // An error. See 11.4
 1483    // but are processors allowed to recover?
 1484    // Hmm according to section 17, the
 1485    // processor must signal these errors
 1486    // and may but need not recover from them.
 1487    // Xalan recovers. Microsoft doesn't.
 1488    }
 1489  0 else if ("Output__78176".equals(id)) {
 1490    // I think the test case is wrong; I see
 1491    // nothing in the spec that says this is
 1492    // an error.
 1493    }
 1494  0 else if (id.startsWith("XSLTFunctions__100")) {
 1495    // I think these test cases are all wrong
 1496    // except perhaps XSLTFunctions__10026; I
 1497    // see nothing in the spec that says this
 1498    // is an error. These are all about the
 1499    // unparsed-entity-uri function.
 1500    }
 1501  0 else if ("Namespace__78027".equals(id)) {
 1502    // Test case is incorrect. This should
 1503    // operate in forwards compatible mode.
 1504    // Xalan gets this right.
 1505    }
 1506  0 else if ("Output_Output_UseStandAloneAttributeWithMultipleRoots".equals(id)) {
 1507    // Error only appears when document is serialized;
 1508    // not before
 1509    }
 1510    else { // transform should have failed
 1511  0 fail("Transformed " + style + "\n id: "
 1512    + testcase.getAttributeValue("id"));
 1513    }
 1514    }
 1515    else {
 1516  216 try {
 1517  216 if ("Attributes_xsl_attribute_dup_attr_with_namespace_conflict".equals(id)
 1518    || "BVTs_bvt057".equals(id)) {
 1519    // This test case requires namespace prefix rewriting,
 1520    // so the output won't be exactly the same between processors
 1521  2 continue;
 1522    }
 1523  214 else if ("Comment_DisableOutputEscaping_XslTextInXslComment".equals(id)) {
 1524    // Test case output is wrong
 1525  1 continue;
 1526    }
 1527  213 else if ("Output__77927".equals(id)
 1528    || "Output__77928".equals(id)
 1529    || "Output__84304".equals(id)
 1530    || "Output__84305".equals(id)
 1531    || "Output__84312".equals(id)
 1532    || "Output__84619".equals(id)
 1533    || "Output__84620".equals(id)
 1534    || "Output_EntityRefInAttribHtml".equals(id)
 1535    ) {
 1536    // These test cases have incorrect line
 1537    // breaks in the reference output.
 1538  0 continue;
 1539    }
 1540  213 else if ("Output_Modified84433".equals(id)) {
 1541    // This test case uses disable output escaping
 1542    // so the results don't match up
 1543  0 continue;
 1544    }
 1545  213 else if ("Sorting_Sort_SortTextWithNonTextCharacters".equals(id)) {
 1546    // Xalan and MSXML don't sort non alphabetic characters
 1547    // exactly the same, but that's legal
 1548  0 continue;
 1549    }
 1550  213 else if ("Text_DoeWithCdataInText".equals(id)) {
 1551    // Requires disable-output-escaping
 1552  0 continue;
 1553    }
 1554  213 else if ("Whitespaces__91443".equals(id)
 1555    || "Whitespaces__91444".equals(id)) {
 1556    // Xalan bug
 1557    // See http://issues.apache.org/jira/browse/XALANJ-1969
 1558  0 continue;
 1559    }
 1560  213 else if ("AVTs__77591".equals(id)) {
 1561    // test suite bug; doesn't escape tabs in output. See
 1562    // http://lists.oasis-open.org/archives/xslt-conformance-comment/200409/msg00017.html
 1563    }
 1564  212 else if ("Keys_MultipltKeysInclude".equals(id) ) {
 1565    // Xalan bug
 1566    // http://issues.apache.org/jira/browse/XALANJ-1956
 1567    }
 1568    /* else if ("Keys_PerfRepro3".equals(id) ) {
 1569    // Suspected Xalan bug
 1570    // http://issues.apache.org/jira/browse/XALANJ-1955
 1571    } */
 1572  211 else if ("Number__84683".equals(id)) {
 1573    // test suite bug
 1574    }
 1575  211 else if ("Number__84687".equals(id)) {
 1576    // test suite bug
 1577    }
 1578  211 else if ("Number__84692".equals(id)) {
 1579    // test suite bug
 1580    }
 1581  211 else if ("Number__84694".equals(id)) {
 1582    // Test suite expects Roman number for zero
 1583    // to be the empty string while Xalan uses 0
 1584    }
 1585  211 else if ("Number__84699".equals(id)) {
 1586    // Xalan bug
 1587    }
 1588  211 else if ("Number__84700".equals(id)) {
 1589    // Xalan bug; extra whitespace. Possibly
 1590    // the same as
 1591    }
 1592  211 else if ("Number__84716".equals(id)) {
 1593    // Xalan doesn't support Russian
 1594    // number formatting
 1595    }
 1596  211 else if ("Number__84717".equals(id)) {
 1597    // Xalan supports more Japanese than the
 1598    // test case does
 1599    }
 1600  211 else if ("Number__84722".equals(id)
 1601    || "Number__84723".equals(id)
 1602    || "Number__84724".equals(id)
 1603    || "Number__84725".equals(id)
 1604    ) {
 1605    // Acceptable locale support differences
 1606    }
 1607  211 else if ("Number_NaNOrInvalidValue".equals(id)) {
 1608    // Double bug! Test case is wrong and
 1609    // Xalan gets this wrong!
 1610    }
 1611  211 else if ("Number_ValueAsNodesetTest1".equals(id)
 1612    || "Number_ValueAsEmptyNodeset".equals(id)) {
 1613    // Another double bug! Test case is wrong and
 1614    // Xalan gets this wrong!
 1615    }
 1616  211 else if (id.equals("XSLTFunctions_BooleanFunction")) {
 1617    // I think the test case is wrong; or perhaps unspecified
 1618    }
 1619  211 else if (id.equals("XSLTFunctions_TestIdFuncInComplexStruct")) {
 1620    // I think the Xalan output white space is wrong;
 1621    // http://issues.apache.org/jira/browse/XALANJ-1947
 1622    }
 1623  211 else if (id.equals("XSLTFunctions__testOn-0.00")) {
 1624    // Possible test suite bug. See
 1625    // http://issues.apache.org/jira/browse/XALANJ-2226
 1626    }
 1627    else {
 1628  211 Document expectedResult;
 1629  71 if (strip) expectedResult = strippingBuilder.build(output);
 1630  140 else expectedResult = builder.build(output);
 1631  63 Document actualResult = XSLTransform.toDocument(result);
 1632  63 assertEquals("Mismatch with " + id,
 1633    expectedResult, actualResult);
 1634    }
 1635    } // end try
 1636    catch (ParsingException ex) {
 1637    // a few of the test cases generate
 1638    // text or HTML output rather than
 1639    // well-formed XML. For the moment, I
 1640    // just skip these.
 1641  145 continue;
 1642    }
 1643    catch (IllegalAddException ex) {
 1644    // A few of the test cases generate
 1645    // incomplete documents so we can't
 1646    // compare output. Perhaps I could
 1647    // wrap in an element, then get children
 1648    // to build a Node object rather than a
 1649    // Document???? i.e. a fragment parser?
 1650    // Could use a SequenceInputStream to hack this
 1651    }
 1652    } // end else
 1653   
 1654    } // end try
 1655    catch (MalformedURIException ex) {
 1656   
 1657    }
 1658    catch (FileNotFoundException ex) {
 1659    // The catalog doesn't always match what's on disk
 1660    }
 1661    catch (UnknownHostException ex) {
 1662    // A few tests like ProcessingInstruction__78197
 1663    // point to external DTD subsets that can't be loaded
 1664    }
 1665    catch (ParsingException ex) {
 1666    // several stylesheets use relative namespace URIs XOM
 1667    // does not support; skip the test
 1668  234 if (ex.getCause() instanceof MalformedURIException) {
 1669  232 continue;
 1670    }
 1671   
 1672  2 String operation = scenario.getAttributeValue("operation");
 1673  2 if (!"execution-error".equals(operation)) {
 1674  0 if ("Namespace_XPath_PredefinedPrefix_XML".equals(id)) {
 1675    // uses relative namespace URIs
 1676    }
 1677  0 else if ("Sorting__78191".equals(id)
 1678    || "Text__78245".equals(id)
 1679    || "Text__78273".equals(id)
 1680    || "Text__78281".equals(id)
 1681    ) {
 1682    // binds XML namespace to prefix other than xml
 1683    }
 1684    else {
 1685  0 System.err.println(id + ": " + ex.getMessage());
 1686  0 throw ex;
 1687    }
 1688    }
 1689    }
 1690    catch (XSLException ex) {
 1691    // If the output was null the transformation
 1692    // was expected to fail
 1693  126 if (output != null) {
 1694  11 Throwable cause = ex.getCause();
 1695  11 if ("Attributes__81487".equals(id)
 1696    || "Attributes__81551".equals(id)) {
 1697    // spec inconsistency; see
 1698    // http://lists.w3.org/Archives/Public/xsl-editors/2004JulSep/0003.html
 1699  2 continue;
 1700    }
 1701  9 else if (cause instanceof MissingResourceException) {
 1702    // Xalan bug;
 1703    // http://issues.apache.org/jira/secure/ManageAttachments.jspa?id=27366
 1704    }
 1705  8 else if ("Include_Include_IncludedStylesheetShouldHaveDifferentBaseUri".equals(id)) {
 1706    // This test case is wrong; Uses backslash in URI
 1707    }
 1708  8 else if ("Elements__89070".equals(id)) {
 1709    // bug fixed in later versions of Xalan
 1710    }
 1711  7 else if ("Namespace-alias_Namespace-Alias_NSAliasForDefaultWithExcludeResPref".equals(id)) {
 1712    // This test case is wrong; it uses a backslash in a URI
 1713    }
 1714  7 else if ("Variables_VariableWithinVariable".equals(id)) {
 1715    // Xalan does not recover from this one
 1716    }
 1717  7 else if ("BVTs_bvt054".equals(id)) {
 1718    // Xalan bug
 1719    // http://issues.apache.org/jira/browse/XALANJ-1952
 1720  1 continue;
 1721    }
 1722  6 else if ("BVTs_bvt094".equals(id)) {
 1723    // Xalan bug
 1724    // http://issues.apache.org/jira/browse/XALANJ-1953
 1725  1 continue;
 1726    }
 1727  5 else if ("Output__78177".equals(id)
 1728    || "Output__84009".equals(id)) {
 1729    // Xalan does not recover from this error
 1730    // which involves duplicate and possibly conflicting xsl:output elements
 1731  0 continue;
 1732    }
 1733  5 else if ("Comment_Comment_CDATAWithSingleHyphen".equals(id)
 1734    || "Comment_Comment_DoubleHypenEntitywithDelCharacter".equals(id)
 1735    || "Comment_Comment_LineOfAllHyphens".equals(id)
 1736    || "Comment_Comment_SingleHyphenOnly".equals(id)
 1737    || "Comment_Comment_DoubleHyphenONLY".equals(id)) {
 1738    // Begins comment data with hyphen, which XOM doesn't allow
 1739  0 continue;
 1740    }
 1741  5 else if ("ProcessingInstruction_ValueOfandTextWithDoeInProcInstr".equals(id)) {
 1742    // Begins processing instruction data with white space, which XOM doesn't allow
 1743  0 continue;
 1744    }
 1745  5 else if ("Elements__89716".equals(id)
 1746    || "Elements__89717".equals(id)
 1747    || "Elements__89718".equals(id)
 1748    || "Output__84309".equals(id)
 1749    || "Namespace__77670".equals(id))
 1750    {
 1751    // Xalan doesn't recover from these, though recovery is allowed
 1752  3 continue;
 1753    }
 1754  2 else if ("Output__84306".equals(id)) {
 1755    // Xalan bug
 1756    // http://issues.apache.org/jira/browse/XALANJ-1954
 1757  0 continue;
 1758    }
 1759  2 else if ("Output__84014".equals(id)) {
 1760    // Fixed in later version of Xalan than is bundled with JDK
 1761  0 continue;
 1762    }
 1763  2 else if (cause instanceof MalformedURIException) {
 1764    // Some of the tests generate relative namespace URIs
 1765    // XOM doesn't support
 1766  2 continue;
 1767    }
 1768    else {
 1769  0 System.out.println(id + ": " + ex.getMessage());
 1770  0 System.out.println("in " + style);
 1771  0 if (cause != null) {
 1772  0 System.out.println("cause: " + cause.getMessage());
 1773    }
 1774  0 throw ex;
 1775    }
 1776    }
 1777    } // end catch
 1778    catch (XMLException ex) {
 1779  0 if ("Text_modified78309".equals(id)) {
 1780    // output is not a full document
 1781    }
 1782    else {
 1783  0 System.err.println(id);
 1784  0 throw ex;
 1785    }
 1786    }
 1787   
 1788    } // end for
 1789   
 1790    } // end if
 1791   
 1792    }
 1793   
 1794   
 1795  1 public void testKeysPerfRepro3()
 1796    throws IOException, ParsingException, XSLException {
 1797   
 1798  1 Builder builder = new Builder();
 1799  1 NodeFactory stripper = new StrippingFactory();
 1800  1 File base = new File("data");
 1801  1 base = new File(base, "oasis-xslt-testsuite");
 1802  1 base = new File(base, "TESTS");
 1803   
 1804  1 File input = new File(base, "MSFT_CONFORMANCE_TESTS/KEYS/input.xml");
 1805  1 File style = new File(base, "MSFT_CONFORMANCE_TESTS/KEYS/input.xsl");
 1806  1 File output = new File(base, "MSFT_CONFORMANCE_TESTS/KEYS/out/PerfRepro3.txt");
 1807   
 1808  1 Document styleDoc = builder.build(style);
 1809  1 Document inputDoc = builder.build(input);
 1810  1 XSLTransform xform = new XSLTransform(styleDoc);
 1811  1 Nodes result = xform.transform(inputDoc);
 1812  1 Document expectedResult = builder.build(output);
 1813  1 Document actualResult = XSLTransform.toDocument(result);
 1814  1 assertEquals(expectedResult, actualResult);
 1815   
 1816    }
 1817   
 1818   
 1819  1 public void testSorting__89749()
 1820    throws IOException, ParsingException, XSLException {
 1821   
 1822  1 Builder builder = new Builder();
 1823  1 NodeFactory stripper = new StrippingFactory();
 1824  1 File base = new File("data");
 1825  1 base = new File(base, "oasis-xslt-testsuite");
 1826  1 base = new File(base, "TESTS");
 1827   
 1828  1 File input = new File(base, "MSFT_CONFORMANCE_TESTS/Sorting/sorttest.xml");
 1829  1 File style = new File(base, "MSFT_CONFORMANCE_TESTS/Sorting/2_5_13_repeat.xsl");
 1830  1 File output = new File(base, "MSFT_CONFORMANCE_TESTS/Sorting/out/89749.txt");
 1831   
 1832  1 Document styleDoc = builder.build(style);
 1833  1 Document inputDoc = builder.build(input);
 1834  1 XSLTransform xform = new XSLTransform(styleDoc);
 1835  1 Nodes result = xform.transform(inputDoc);
 1836    /*Document expectedResult = builder.build(output);
 1837    Document actualResult = XSLTransform.toDocument(result);
 1838    assertEquals(expectedResult, actualResult); */
 1839   
 1840    }
 1841   
 1842   
 1843  1 public void testToDocumentWithEmptyNodes() {
 1844   
 1845  1 try {
 1846  1 XSLTransform.toDocument(new Nodes());
 1847  0 fail("Converted empty nodes to document");
 1848    }
 1849    catch (XMLException success) {
 1850  1 assertNotNull(success.getMessage());
 1851    }
 1852   
 1853    }
 1854   
 1855   
 1856  1 public void testToDocumentWithNoRoot() {
 1857   
 1858  1 Nodes input = new Nodes();
 1859  1 input.append(new Comment("data"));
 1860  1 try {
 1861  1 XSLTransform.toDocument(new Nodes());
 1862  0 fail("Converted comment to document");
 1863    }
 1864    catch (XMLException success) {
 1865  1 assertNotNull(success.getMessage());
 1866    }
 1867   
 1868    }
 1869   
 1870   
 1871  1 public void testToDocumentWithText() {
 1872   
 1873  1 Nodes input = new Nodes();
 1874  1 Element root = new Element("root");
 1875  1 Comment comment = new Comment("data");
 1876  1 ProcessingInstruction pi = new ProcessingInstruction("target", "data");
 1877  1 input.append(comment);
 1878  1 input.append(root);
 1879  1 input.append(pi);
 1880  1 input.append(new Text("text"));
 1881  1 try {
 1882  1 XSLTransform.toDocument(new Nodes());
 1883  0 fail("Converted text to document");
 1884    }
 1885    catch (XMLException success) {
 1886  1 assertNotNull(success.getMessage());
 1887    }
 1888   
 1889    }
 1890   
 1891   
 1892  1 public void testToDocumentWithAttribute() {
 1893   
 1894  1 Nodes input = new Nodes();
 1895  1 Element root = new Element("root");
 1896  1 Comment comment = new Comment("data");
 1897  1 ProcessingInstruction pi = new ProcessingInstruction("target", "data");
 1898  1 input.append(comment);
 1899  1 input.append(root);
 1900  1 input.append(pi);
 1901  1 input.append(new Attribute("name", "text"));
 1902  1 try {
 1903  1 XSLTransform.toDocument(new Nodes());
 1904  0 fail("Converted text to document");
 1905    }
 1906    catch (XMLException success) {
 1907  1 assertNotNull(success.getMessage());
 1908    }
 1909   
 1910    }
 1911   
 1912   
 1913  1 public void testToDocumentWithDocType() {
 1914   
 1915  1 Nodes input = new Nodes();
 1916  1 Element root = new Element("root");
 1917  1 DocType doctype = new DocType("root");
 1918  1 Comment comment = new Comment("data");
 1919  1 ProcessingInstruction pi = new ProcessingInstruction("target", "data");
 1920  1 input.append(comment);
 1921  1 input.append(doctype);
 1922  1 input.append(root);
 1923  1 input.append(pi);
 1924  1 Document output = XSLTransform.toDocument(input);
 1925  1 assertEquals(root, output.getRootElement());
 1926  1 assertEquals(comment, output.getChild(0));
 1927  1 assertEquals(doctype, output.getChild(1));
 1928  1 assertEquals(pi, output.getChild(3));
 1929  1 assertEquals(input.size(), output.getChildCount());
 1930   
 1931    }
 1932   
 1933   
 1934  1 public void testToDocumentWithDocTypeInEpilog() {
 1935   
 1936  1 Nodes input = new Nodes();
 1937  1 Element root = new Element("root");
 1938  1 DocType doctype = new DocType("root");
 1939  1 Comment comment = new Comment("data");
 1940  1 ProcessingInstruction pi = new ProcessingInstruction("target", "data");
 1941  1 input.append(comment);
 1942  1 input.append(root);
 1943  1 input.append(doctype);
 1944  1 input.append(pi);
 1945  1 try {
 1946  1 XSLTransform.toDocument(input);
 1947  0 fail("Allowed doctype in epilog");
 1948    }
 1949    catch (XMLException success) {
 1950  1 assertNotNull(success.getMessage());
 1951    }
 1952   
 1953    }
 1954   
 1955   
 1956  1 public void testToDocumentWithDoubleRoot() {
 1957   
 1958  1 Nodes input = new Nodes();
 1959  1 Element root = new Element("root");
 1960  1 Comment comment = new Comment("data");
 1961  1 input.append(comment);
 1962  1 input.append(root);
 1963  1 input.append(new Element("root2"));
 1964  1 try {
 1965  1 XSLTransform.toDocument(input);
 1966  0 fail("Allowed two root elements");
 1967    }
 1968    catch (XMLException success) {
 1969  1 assertNotNull(success.getMessage());
 1970    }
 1971   
 1972    }
 1973   
 1974   
 1975  1 public void testToDocumentWithSingleRoot() {
 1976   
 1977  1 Nodes input = new Nodes();
 1978  1 Element root = new Element("root");
 1979  1 input.append(root);
 1980  1 Document output = XSLTransform.toDocument(input);
 1981  1 assertEquals(root, output.getRootElement());
 1982  1 assertEquals(input.size(), output.getChildCount());
 1983   
 1984    }
 1985   
 1986   
 1987  1 public void testToDocumentWithPrologAndEpilog() {
 1988   
 1989  1 Nodes input = new Nodes();
 1990  1 Element root = new Element("root");
 1991  1 Comment comment = new Comment("data");
 1992  1 ProcessingInstruction pi = new ProcessingInstruction("target", "data");
 1993  1 input.append(comment);
 1994  1 input.append(root);
 1995  1 input.append(pi);
 1996  1 Document output = XSLTransform.toDocument(input);
 1997  1 assertEquals(root, output.getRootElement());
 1998  1 assertEquals(comment, output.getChild(0));
 1999  1 assertEquals(pi, output.getChild(2));
 2000  1 assertEquals(input.size(), output.getChildCount());
 2001   
 2002    }
 2003   
 2004   
 2005    }