java xslt 教程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/968040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:42:57  来源:igfitidea点击:

java xslt tutorial

javaxslt

提问by

Can any one suggest good XSLT with java tutorials?

任何人都可以通过java教程推荐好的XSLT吗?

回答by Dana the Sane

The Sun Java website is usually a good place to begin, here's an article for J2EE.

Sun Java 网站通常是一个很好的起点,这里有一篇关于J2EE的文章。

回答by victor hugo

I use Apache Xalan so I recommend you to learn it

我使用 Apache Xalan 所以我建议你学习它

If you don't know XSL w3schools has a good one for getting started

如果您不知道 XSL w3schools 有一个很好的入门指南

回答by Francois Gravel

There are three stepsto learning XSLT on Java:

在 Java 上学习 XSLT需要三个步骤

1- Pick a XSLT engine.

1- 选择一个 XSLT 引擎。

Each engine is slightly different, but for basic processing any will do.

每个引擎都略有不同,但对于基本处理,任何引擎都可以。

Xalan has always worked well for me. To get started, all you need to do is download the Xalan jar(s) from hereand put them in your project's classpath. The file you need is one of the xalan-j_X_X_X-bin-2jarsfiles.

Xalan 对我来说一直都很好。首先,您需要做的就是从这里下载 Xalan jar并将它们放在您项目的类路径中。您需要的文件是其中一个xalan-j_X_X_X-bin-2jars文件。

Then use the following code to process a sample XML within a Java program (adapted from SimpleTransform.java, not tested):

然后使用以下代码在 Java 程序中处理示例 XML(改编自 SimpleTransform.java,未测试):

public class SimpleTransform {
  public static void main(String[] args) {
        try {  
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer = tFactory.newTransformer(new StreamSource("transform.xslt"));
      transformer.transform(new StreamSource("input.xml"), new StreamResult(new FileOutputStream("output.out")));
      System.out.println("************* The result is in output.out *************");
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }
}

2- Learn XPath.

2- 学习 XPath。

XPath is the syntax used to select elements within an input XML file.

XPath 是用于在输入 XML 文件中选择元素的语法。

It also allows provided basic functions to do some processing. Although XPath is a major part of XSLT, it can be used independently to process XML files.

它还允许提供的基本功能进行一些处理。尽管 XPath 是 XSLT 的主要部分,但它可以独立用于处理 XML 文件。

For example, Dom4j and most XML parsers provide the ability to select elements using the XPath syntax. I can't recommend any specific tutorial, but searching XPath tutorialprovides a number of good results.

例如,Dom4j 和大多数 XML 解析器提供使用 XPath 语法选择元素的能力。我不能推荐任何特定的教程,但搜索 XPath 教程提供了许多不错的结果。

3- Learn the XSLT format.

3- 学习 XSLT 格式。

XSLT is simply XML. The XSLT specification can be found here.

XSLT 只是 XML。可以在此处找到 XSLT 规范。

There are plenty of tutorials out there. Just start from a simple example and build your knowledge from there. Some of the key points to remember:

那里有很多教程。只需从一个简单的示例开始,然后从那里构建您的知识。要记住的一些关键点:

  • XSLT is based on a functional language. If you try to use it as a procedural language, you will end up with difficult to maintain XSLT files. Related question on that topic.
  • You can't modify variables. You can declare and assign values to variables, but you can't modify them. I remember hitting a wall a few times because of this.
  • XSLT 基于函数式语言。如果您尝试将其用作过程语言,则最终将难以维护 XSLT 文件。 关于该主题的相关问题
  • 您不能修改变量。您可以为变量声明和赋值,但不能修改它们。我记得因为这个原因撞了几次墙。