Wie kann ich die XSLT 2.0-und XSLT 3.0 in Java?
Ich bin in der Lage, mithilfe von XSLT 1.0 in Java wie im folgenden Beispiel :-
copy.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="identityxfm.xsl"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with
XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen of the
world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology society
in England, the young survivors lay the foundation for a new
society.</description>
</book>
</catalog>
kopieren.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/| @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Copy.java
package com.data.transform;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Copy {
public static void main(String args[]) throws Exception {
StreamSource source = new StreamSource("copy.xml");
StreamSource stylesource = new StreamSource("copy.xsl");
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(stylesource);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
}
}
Ausgabe
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="identityxfm.xsl"?><catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with
XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen of the
world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology society
in England, the young survivors lay the foundation for a new
society.</description>
</book>
</catalog>
Aber jetzt will ich mit paar Dinge, die enthalten sind in XSLT 2.0 und XSLT 3.0 (wie xsl:analyze-string
, xsl:try
etc.) in Java. Wie kann ich das tun ?
- Verwenden Sie eine Java-Bibliothek implementieren. Die Suche im web zu finden.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Sich Saxon 9 ER von Maven oder Sourceforge und legte es auf den classpath, dann haben Sie die XSLT-2.0-Unterstützung mit Saxon 9.x bevor 9.8-oder XSLT 3.0-Unterstützung (außer streaming höherer Ordnung Funktionen,
xsl:evaluate
-, schema-Bewusstsein, rückwärts-Kompatibilität) mit 9.8. Für die vollständige XSLT 3.0-Unterstützung, die Sie brauchen download Saxon 9 PE oder EE ab Saxonica und legen Sie Sie zusammen mit einem Lizenz Sie kaufen oder eine trial Lizenz, die Sie anfordern, auf dem Klassenpfad.