当前位置: 首页>>代码示例>>Java>>正文


Java XsltTransformer类代码示例

本文整理汇总了Java中net.sf.saxon.s9api.XsltTransformer的典型用法代码示例。如果您正苦于以下问题:Java XsltTransformer类的具体用法?Java XsltTransformer怎么用?Java XsltTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XsltTransformer类属于net.sf.saxon.s9api包,在下文中一共展示了XsltTransformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCustomParameters

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
private void setCustomParameters(XsltTransformer xsltTransformer) throws XPathException {
	//logger.info("setCustomParameters()");
	final URL 				scriptUrl 		= getScriptUrl();
	final XsltExecutable 	xsltExecutable 	= xsltConrefCache.getTransformerCache().getExecutable(scriptUrl, xsltConrefCache.getUriResolver());
	final List<String> attrNameList = node.getAttributeNamesOfNamespace(NAMESPACE_PARAMETER_URI);
	for (String attrName : attrNameList) {
		//logger.info("attribute: " + attrName);
		final QName 	paramName 	= new QName(attrName.replaceAll("(^[^\\{\\}]*:)|(^\\{.*\\})", ""));
		final String 	paramValue	= node.getAttribute(attrName, NAMESPACE_PARAMETER_URI);
		//logger.info("set custom parameter: " + paramName + " = '" + paramValue + "'");
		if (paramValue != null) {
			if (xsltExecutable.getGlobalParameters().containsKey(paramName)) {
				try {
					xsltTransformer.setParameter(paramName, new XdmAtomicValue(EmbeddedXPathResolver.resolve(paramValue, node), ItemType.UNTYPED_ATOMIC));
					//logger.info("parameters set. ");
				} catch (SaxonApiException e) {
					logger.error(e, e);
				}
			} else {
				//logger.error("Parameter '" + paramName + "' not defined in script.");
			}
		}
	}
}
 
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:25,代码来源:XsltConref.java

示例2: extractString

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
private String extractString(SaxonNodeWrapper node, String xslUrl) {
	try {
		final XsltExecutable 	executable 		= bookCache.getExtractTransformerCache().getExecutable(new URL(bookCache.getDitaOtUrl(), xslUrl));
		final XsltTransformer 	xsltTransformer = executable.load();
		xsltTransformer.setInitialContextNode(new XdmNode(node.getNodeInfo()));
		
		final XdmDestination destination = new XdmDestination();
		xsltTransformer.setDestination(destination);
		xsltTransformer.transform();
		
		return destination.getXdmNode().getStringValue();
	} catch (Exception e) {
		logger.error(e, e);
		return "<ERR>";
	}
}
 
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:17,代码来源:FileCache.java

示例3: transform

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
/**
 * Transforms an inputstream based on a template and an xsl.
 * @param xslInputStream the xsl as an {@link InputStream}
 * @param requestInputStream the request as an {@link InputStream}
 * @param templateInputStream the template as an {@link InputStream}
 * @param nameToXml the names identifying a request or response and their bodies
 * @return the result of the transformation
 * @throws SaxonApiException it is thrown if an exception occurs during the xsl transformation
 * @throws SAXException it is thrown if an exception occurs during the xsl transformation
 */
public byte[] transform(final InputStream xslInputStream, final InputStream requestInputStream, final InputStream templateInputStream,
        final Map<String, String> nameToXml) throws SaxonApiException, SAXException {
    Processor processor = processorFactory.createProcessor();
    XMLReader xmlReader = createXMLReader();
    //xsl compilation
    XsltExecutable xsltExecutable = xslCompiler.compileXsl(xslInputStream, processor);
    XsltTransformer xsltTransformer = xsltExecutable.load();
    //set the output
    ByteArrayOutputStream output = xslOutputProvider.getOutput(xsltTransformer);
    //set the request
    setRequest(requestInputStream, processor, xsltTransformer);
    setSessionEntities(nameToXml, processor, xsltTransformer);
    //set the template
    setTemplate(templateInputStream, processor, xmlReader, xsltTransformer);
    xsltTransformer.transform();
    return output.toByteArray();
}
 
开发者ID:epam,项目名称:Wilma,代码行数:28,代码来源:SequenceAwareXslTransformer.java

示例4: doProcess2

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
@Override
protected boolean doProcess2(Record inputRecord, InputStream stream) throws SaxonApiException, XMLStreamException {
  incrementNumRecords();      
  for (Fragment fragment : fragments) {
    Record outputRecord = inputRecord.copy();
    removeAttachments(outputRecord);   
    XdmNode document = parseXmlDocument(stream);
    LOG.trace("XSLT input document: {}", document);
    XsltTransformer evaluator = fragment.transformer;
    evaluator.setInitialContextNode(document);
    XMLStreamWriter morphlineWriter = new MorphlineXMLStreamWriter(getChild(), outputRecord);
    evaluator.setDestination(new XMLStreamWriterDestination(morphlineWriter));
    evaluator.transform(); //  run the query and push into child via RecordXMLStreamWriter
  }      
  return true;
}
 
开发者ID:cloudera,项目名称:cdk,代码行数:17,代码来源:XSLTBuilder.java

示例5: doTest

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
@Test
public void doTest() throws SaxonApiException, FileNotFoundException, IOException {
    Configuration config = Configuration.newConfiguration();
    Processor processor = new Processor(config);
    XsltTransformer transformer = processor.newXsltCompiler().compile(new StreamSource("src/test/resources/identity.xsl")).load();
    Serializer serializer = processor.newSerializer(new File("target/generated-test-files/output.xml"));
    FileAppenderStep fas = new FileAppenderStep();
    fas.setParameter(FileAppenderStep.FILE_NAME, new XdmAtomicValue("target/generated-test-files/appendee.txt"));
    fas.setParameter(FileAppenderStep.VALUE, new XdmAtomicValue("blablabla"));
    fas.setParameter(FileAppenderStep.LINE_SEPARATOR, new XdmAtomicValue("LF"));
    fas.setDestination(serializer);
    transformer.setDestination(fas);
    transformer.setSource(new StreamSource("src/test/resources/source.xml"));
    File expect = new File("target/generated-test-files/appendee.txt");
    if(expect.exists()) expect.delete();
    transformer.transform();
    assertTrue(expect.isFile());
    BufferedReader br = new BufferedReader(new FileReader(expect));
    char[] buff = new char[30];
    int ret = br.read(buff);
    br.close();
    assertEquals(10, ret);
    char[] ex = new char[] { 'b', 'l', 'a', 'b', 'l', 'a', 'b', 'l', 'a', '\n'};
    assertArrayEquals(ex, Arrays.copyOf(buff, ret));
    fas.setDestination(processor.newSerializer(new File("target/generated-test-files/output2.xml")));
    transformer.transform();
    br = new BufferedReader(new FileReader(expect));
    ret = br.read(buff);
    br.close();
    assertEquals(20, ret);
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:32,代码来源:FileAppenderStepTest.java

示例6: getOutput

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
/** Retrieves the output for a given xslt transformer.
 * @param xsltTransformer the {@link XsltTransformer} that will receive the output
 * @return the output as a {@link ByteArrayOutputStream}
 */
public ByteArrayOutputStream getOutput(final XsltTransformer xsltTransformer) {
    Serializer serializer = serializerFactory.createSerializer();
    serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
    serializer.setOutputProperty(Serializer.Property.INDENT, "no");
    ByteArrayOutputStream output = byteArrayOutputStreamFactory.createByteArrayOutputStream();
    serializer.setOutputStream(output);
    xsltTransformer.setDestination(serializer);
    return output;
}
 
开发者ID:epam,项目名称:Wilma,代码行数:14,代码来源:XslOutputProvider.java

示例7: transform

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
/**
 * Transforms an inputstream based on a template and an xsl.
 * @param xslInputStream the xsl as an {@link InputStream}
 * @param requestInputStream the request as an {@link InputStream}
 * @param templateInputStream the template as an {@link InputStream}
 * @return the result of the transformation
 * @throws SaxonApiException it is thrown if an exception occurs during the xsl transformation
 * @throws SAXException it is thrown if an exception occurs during the xsl transformation
 */
public byte[] transform(final InputStream xslInputStream, final InputStream requestInputStream, final InputStream templateInputStream)
    throws SaxonApiException, SAXException {
    Processor processor = processorFactory.createProcessor();
    XMLReader xmlReader = createXMLReader();
    //xsl compilation
    XsltExecutable xsltExecutable = xslCompiler.compileXsl(xslInputStream, processor);
    XsltTransformer xsltTransformer = xsltExecutable.load();
    //set the output
    ByteArrayOutputStream output = xslOutputProvider.getOutput(xsltTransformer);
    //set the request
    setRequest(requestInputStream, processor, xsltTransformer);
    //set the template
    setTemplate(templateInputStream, processor, xmlReader, xsltTransformer);
    xsltTransformer.transform();
    return output.toByteArray();
}
 
开发者ID:epam,项目名称:Wilma,代码行数:26,代码来源:XslTransformer.java

示例8: setTemplate

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
private void setTemplate(final InputStream templateInputStream, final Processor processor, final XMLReader xmlReader,
        final XsltTransformer xsltTransformer) throws SaxonApiException {
    InputSource inputSource = inputSourceFactory.createInputSource(templateInputStream);
    Source templateSource = saxSourceFactory.createSAXSource(xmlReader, inputSource);
    XdmNode templateNode = processor.newDocumentBuilder().build(templateSource);
    xsltTransformer.setInitialContextNode(templateNode);
}
 
开发者ID:epam,项目名称:Wilma,代码行数:8,代码来源:XslTransformer.java

示例9: setRequest

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
private void setRequest(final InputStream requestInputStream, final Processor processor, final XsltTransformer xsltTransformer)
    throws SaxonApiException {
    StreamSource requestStreamSource = streamSourceFactory.createStreamSource(requestInputStream);
    XdmNode requestDocument = processor.newDocumentBuilder().build(requestStreamSource);
    QName requestName = qNameFactory.createQName(REQUEST_PARAMETER_NAME);
    xsltTransformer.setParameter(requestName, requestDocument);
}
 
开发者ID:epam,项目名称:Wilma,代码行数:8,代码来源:XslTransformer.java

示例10: setSessionEntities

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
private void setSessionEntities(final Map<String, String> nameToXml, final Processor processor, final XsltTransformer xsltTransformer)
    throws SaxonApiException {
    for (Entry<String, String> entry : nameToXml.entrySet()) {
        InputStream parameterInputStream = inputStreamFactory.createByteArrayInputStream(entry.getValue().getBytes());
        setParameter(parameterInputStream, processor, xsltTransformer, entry.getKey());
    }
}
 
开发者ID:epam,项目名称:Wilma,代码行数:8,代码来源:SequenceAwareXslTransformer.java

示例11: setParameter

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
private void setParameter(final InputStream parameterInputStream, final Processor processor, final XsltTransformer xsltTransformer,
        final String parameterName) throws SaxonApiException {
    StreamSource requestStreamSource = streamSourceFactory.createStreamSource(parameterInputStream);
    XdmNode requestDocument = processor.newDocumentBuilder().build(requestStreamSource);
    QName parameter = qNameFactory.createQName(parameterName);
    xsltTransformer.setParameter(parameter, requestDocument);
}
 
开发者ID:epam,项目名称:Wilma,代码行数:8,代码来源:SequenceAwareXslTransformer.java

示例12: transform

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
/**
 * Transforms the content of a DOM Node using a specified XSLT stylesheet.
 *
 * @param xslt
 *            A Source object representing a stylesheet (XSLT 1.0 or 2.0).
 * @param source
 *            A Node representing the XML source. If it is an Element node
 *            it will be imported into a new DOM Document.
 * @return A DOM Document containing the result of the transformation.
 */
public static Document transform(Source xslt, Node source) {
    Document sourceDoc = null;
    Document resultDoc = null;
    try {
        resultDoc = DocumentBuilderFactory.newInstance()
                .newDocumentBuilder().newDocument();
        if (source.getNodeType() == Node.DOCUMENT_NODE) {
            sourceDoc = (Document) source;
        } else {
            sourceDoc = DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder().newDocument();
            sourceDoc.appendChild(sourceDoc.importNode(source, true));
        }
    } catch (ParserConfigurationException pce) {
        throw new RuntimeException(pce);
    }
    Processor processor = new Processor(false);
    XsltCompiler compiler = processor.newXsltCompiler();
    try {
        XsltExecutable exec = compiler.compile(xslt);
        XsltTransformer transformer = exec.load();
        transformer.setSource(new DOMSource(sourceDoc));
        transformer.setDestination(new DOMDestination(resultDoc));
        transformer.transform();
    } catch (SaxonApiException e) {
        throw new RuntimeException(e);
    }
    return resultDoc;
}
 
开发者ID:opengeospatial,项目名称:ets-osxgeotime10,代码行数:40,代码来源:XMLUtils.java

示例13: checkConformance

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
/**
 * Check conformance to TAXII specification beyond what XML Schema provides. 
 */
private void checkConformance(Object m, 
        ValidationErrorHandler errorHandler) {
    final XsltTransformer transformer = schematronValidator.load();
    transformer.setMessageListener(errorHandler);
    try {
        transformer.setSource(new JAXBSource(jaxbContext, m));
        transformer.setDestination(new SAXDestination(new DefaultHandler()));
        transformer.transform();
    } 
    catch (SaxonApiException | JAXBException e) {
        errorHandler.getResults().addError("Conformance error: " + e.getMessage());
    } 
}
 
开发者ID:TAXIIProject,项目名称:java-taxii,代码行数:17,代码来源:TaxiiXml.java

示例14: executeTemplate

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
public XdmNode executeTemplate(TemplateEntry template, XdmNode params,
        XPathContext context) throws Exception {
  if (stop) {
    throw new Exception("Execution was stopped by the user.");
  }
  XsltExecutable executable = engine.loadExecutable(template,
          opts.getSourcesName());
  XsltTransformer xt = executable.load();
  XdmDestination dest = new XdmDestination();
  xt.setDestination(dest);
  if (template.usesContext() && context != null) {
    xt.setSource((NodeInfo) context.getContextItem());
  } else {
    xt.setSource(new StreamSource(new StringReader("<nil/>")));
  }
      xt.setParameter(TECORE_QNAME, new ObjValue(this));
  if (params != null) {
          xt.setParameter(TEPARAMS_QNAME, params);
  }
  // test may set global verdict, e.g. by calling ctl:fail
  if (LOGR.isLoggable( FINE)) {
    LOGR.log( FINE,
            "Executing TemplateEntry {0}" + template.getQName());
  }
  xt.transform();
  XdmNode ret = dest.getXdmNode();
      if (ret != null && LOGR.isLoggable( FINE)) {
          LOGR.log( FINE, "Output:\n" + ret.toString());
      }
  return ret;
}
 
开发者ID:opengeospatial,项目名称:teamengine,代码行数:32,代码来源:TECore.java

示例15: setStart

import net.sf.saxon.s9api.XsltTransformer; //导入依赖的package包/类
public void setStart(XsltTransformer start) {
    this.start = start;
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:4,代码来源:DoubleDestination.java


注:本文中的net.sf.saxon.s9api.XsltTransformer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。