Project

Profile

Help

Revision d61f99bb

Added by Michael Kay 3 months ago

Fix bug 4929

View differences:

src/main/java/net/sf/saxon/stax/ReceiverToXMLStreamWriter.java
118 118
                if (attPrefix.equals("") && attUri.equals("")) {
119 119
                    writer.writeAttribute(attLocal, value);
120 120
                } else if (attPrefix.equals("") & !attUri.equals("")) {
121
                    writer.writeAttribute(uri, local, value);
121
                    writer.writeAttribute(attUri, attLocal, value);
122 122
                } else {
123
                    writer.writeAttribute(prefix, uri, local, value);
123
                    writer.writeAttribute(attPrefix, attUri, attLocal, value);
124 124
                }
125 125
            }
126 126
        } catch (XMLStreamException e) {
src/test/java/s9apitest/TestSerializer.java
6 6
import net.sf.saxon.jaxp.TransformerImpl;
7 7
import net.sf.saxon.lib.Feature;
8 8
import net.sf.saxon.lib.FeatureKeys;
9
import net.sf.saxon.lib.NamespaceConstant;
9 10
import net.sf.saxon.lib.OutputURIResolver;
10 11
import net.sf.saxon.s9api.*;
12
import net.sf.saxon.stax.XMLStreamWriterDestination;
11 13
import org.junit.jupiter.api.Test;
12 14
import org.xml.sax.ContentHandler;
13 15
import org.xml.sax.InputSource;
14 16
import org.xml.sax.XMLReader;
15 17

  
16 18
import javax.xml.parsers.SAXParserFactory;
19
import javax.xml.stream.XMLStreamWriter;
17 20
import javax.xml.transform.Result;
18 21
import javax.xml.transform.Transformer;
19 22
import javax.xml.transform.TransformerException;
......
21 24
import javax.xml.transform.sax.SAXSource;
22 25
import javax.xml.transform.stream.StreamResult;
23 26
import javax.xml.transform.stream.StreamSource;
24
import java.io.*;
27
import java.io.ByteArrayOutputStream;
28
import java.io.File;
29
import java.io.StringReader;
30
import java.io.StringWriter;
25 31

  
26 32
import static net.sf.saxon.s9api.streams.Steps.child;
27
import static org.junit.jupiter.api.Assertions.*;
33
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertFalse;
35
import static org.junit.jupiter.api.Assertions.assertTrue;
36
import static org.junit.jupiter.api.Assertions.fail;
28 37

  
29 38
/**
30 39
 * JUnit tests for the s9api XQueryCompiler
......
455 464
        }
456 465
    }
457 466

  
467
    @Test
468
    public void testXmlStreamWriter() {    // Bug 4929
469
        try {
470
            String xsl = "<xsl:stylesheet \n"
471
                    + "  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n"
472
                    + "  exclude-result-prefixes=\"#all\"\n"
473
                    + "  version=\"3.0\">\n"
474
                    + "  \n"
475
                    + "  <xsl:mode on-no-match=\"shallow-copy\"/>\n"
476
                    + "  \n"
477
                    + "</xsl:stylesheet>";
478
            Processor processor = new Processor(false);
479
            XdmNode inputDoc = processor.newDocumentBuilder().build(new File(ConfigTest.DATA_DIR + "renvooi.xml"));
480
            StringWriter sw = new StringWriter();
481
            Serializer serializer = processor.newSerializer(sw);
482
            XMLStreamWriter xsw = serializer.getXMLStreamWriter();
483
            XsltExecutable executable = processor.newXsltCompiler().compile(new StreamSource(new StringReader(xsl)));
484
            executable.load30().applyTemplates(inputDoc, new XMLStreamWriterDestination(xsw));
485

  
486
            XdmNode result = processor.newDocumentBuilder().build(new StreamSource(new StringReader(sw.toString())));
487
            XdmFunctionItem deepEq = XdmFunctionItem.getSystemFunction(
488
                    processor, new QName(NamespaceConstant.FN, "deep-equal"), 2);
489
            assert deepEq != null;
490
            XdmValue compare = deepEq.call(processor, inputDoc, result);
491
            assertTrue(compare instanceof XdmAtomicValue);
492
            assertTrue(((XdmAtomicValue)compare).getBooleanValue());
493

  
494
        } catch (Exception e) {
495
            e.printStackTrace(System.err);
496
        }
497
    }
498

  
458 499
//    public void testBulkIndent() {
459 500
          // Test to check that indentation produces reasonable results. Commented out because
460 501
          // there is no automated checking of the results, it relies on visual inspection.

Also available in: Unified diff