I could use assistance here. Given an xml such as: <report reportId="123"> <animal>cat</animal> </report>
My embedded FOP transformation is handling elements but not attributes. Here is the code as a Nabble attachment: http://old.nabble.com/file/p26489602/attributetest.zip attributetest.zip -- if you have Maven on your machine, "mvn clean install exec:exec" will quickly and easily show the problem. Here is the code within the attachment: public class AttributeTest { .... private void run() { try { // works fine -- both animal element and reportId attribute in pdf URL fileURL = getClass().getClassLoader().getResource("attr.xml"); Source rptSource = new StreamSource(fileURL.toString()); OutputStream outStream = new java.io.FileOutputStream("1pdfdirect.pdf"); FopFactory fopFactory = FopFactory.newInstance(); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, outStream); Result res = new SAXResult(fop.getDefaultHandler()); URL stylesheetURL = getClass().getClassLoader().getResource("AttributeTest.xsl"); TransformerFactory factory = TransformerFactory.newInstance(); Transformer t = factory.newTransformer(new StreamSource(stylesheetURL.toString())); t.transform(rptSource, res); outStream.close(); // does not work -- has animal element but not reportId attribute in pdf Source rptSource2 = new SAXSource(new ReportXMLBuilder(), new EmptyInputSource()); OutputStream outStream2 = new java.io.FileOutputStream("2pdfViaReader.pdf"); Fop fop2 = fopFactory.newFop(MimeConstants.MIME_PDF, outStream2); Result res2 = new SAXResult(fop2.getDefaultHandler()); t.transform(rptSource2, res2); outStream2.close(); // but oddly, this *does* work -- keeps reportId attribute Source rptSource3 = new SAXSource(new ReportXMLBuilder(), new EmptyInputSource()); Transformer t2 = factory.newTransformer(); Result res3 = new StreamResult("3xmloutput.xml"); // has reportId attribute t2.transform(rptSource3, res3); } catch (Exception e) { e.printStackTrace(System.out); } } // AbstractXMLBuilder is here: http://tinyurl.com/ye4c39h public static class ReportXMLBuilder extends AbstractXMLBuilder { public void parse(InputSource input) throws IOException, SAXException { handler.startDocument(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "reportId", "", "123"); handler.startElement("report", atts); handler.element("animal", "cat"); handler.endElement("report"); handler.endDocument(); } } ... } Can anyone see what I'm doing wrong? Thanks, Glen J.Pietschmann wrote: > > Both approaches work for me (the first is the canonical one). > > I suspect your original problem is somewhat different, common > problems are misspellings, wrong context and namespace confusions. > You might get more help if you cut&paste the actual xml and > xslt code into the mail. > > J.Pietschmann > -- View this message in context: http://old.nabble.com/Problem-using-attributes-with-%3Cxsl%3Avalue-of-select%3D%22%22-%3E-tp26451537p26489602.html Sent from the FOP - Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org