@Test public void testRecursiveCopyExtraRules() throws Exception { String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString(SAMPLE_TRANSFORMER_RECURSIVE_COPY); String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of( "extra_rules", "<xsl:template match=\"nested\"><empty_nest/></xsl:template>")); String input = "<entity myattrib=\"myval\">"+NEWLINE+ " <type myattrib2=\"myval2\">mytype</type>"+NEWLINE+ " <nested>"+NEWLINE+ " <type myattrib3=\"myval3\">foo</type>"+NEWLINE+ " bar"+NEWLINE+ " </nested>"+NEWLINE+ " <id>myid</id>"+NEWLINE+ "</entity>"; String expected = "<entity myattrib=\"myval\">"+NEWLINE+ " <type myattrib2=\"myval2\">mytype</type>"+NEWLINE+ " <empty_nest/>"+NEWLINE+ " <id>myid</id>"+NEWLINE+ "</entity>"; XsltTransformer transformer = new XsltTransformer(xslt); String result = transformer.transform(input); assertEquals(result, expected); }
public String transform(String input) throws IOException, URISyntaxException, TransformerException { StreamSource xslt = new StreamSource(new ByteArrayInputStream(xsltContent.getBytes())); Transformer transformer = factory.newTransformer(xslt); Source text = new StreamSource(new ByteArrayInputStream(input.getBytes())); ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length()); transformer.transform(text, new StreamResult(baos)); return new String(baos.toByteArray()); }
XsltTransformer implements RawDataTransformer { public String transform(String input) throws IOException, URISyntaxException, TransformerException { StreamSource xslt = new StreamSource(new ByteArrayInputStream(xsltContent.getBytes())); Transformer transformer = factory.newTransformer(xslt); Source text = new StreamSource(new ByteArrayInputStream(input.getBytes())); ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length()); transformer.transform(text, new StreamResult(baos)); return new String(baos.toByteArray()); } }
XsltTransformer implements RawDataTransformer { public String transform(String input) throws IOException, URISyntaxException, TransformerException { StreamSource xslt = new StreamSource(new ByteArrayInputStream(xsltContent.getBytes())); Transformer transformer = factory.newTransformer(xslt); Source text = new StreamSource(new ByteArrayInputStream(input.getBytes())); ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length()); transformer.transform(text, new StreamResult(baos)); return new String(baos.toByteArray()); } XsltTransformer(String xsltContent); }
XsltTransformer implements RawDataTransformer { public String transform(String input) throws IOException, URISyntaxException, TransformerException { StreamSource xslt = new StreamSource(new ByteArrayInputStream(xsltContent.getBytes())); Transformer transformer = factory.newTransformer(xslt); Source text = new StreamSource(new ByteArrayInputStream(input.getBytes())); ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length()); transformer.transform(text, new StreamResult(baos)); return new String(baos.toByteArray()); } XsltTransformer(String xsltContent); String transform(String input); }
XsltTransformer implements RawDataTransformer { public String transform(String input) throws IOException, URISyntaxException, TransformerException { StreamSource xslt = new StreamSource(new ByteArrayInputStream(xsltContent.getBytes())); Transformer transformer = factory.newTransformer(xslt); Source text = new StreamSource(new ByteArrayInputStream(input.getBytes())); ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length()); transformer.transform(text, new StreamResult(baos)); return new String(baos.toByteArray()); } XsltTransformer(String xsltContent); String transform(String input);  }