如何在eclipse indigo和JAVA中使用Saxon(XSLT 2.0处理器)
我必须使用XSLT 2.0处理器处理字符串操作函数,如如何在eclipse indigo和JAVA中使用Saxon(XSLT 2.0处理器),java,eclipse,saxon,Java,Eclipse,Saxon,我必须使用XSLT 2.0处理器处理字符串操作函数,如replace()。我在POM文件中添加了对saxon的依赖,并运行了“mvn安装”命令。通过这样做,“saxon-9.1.0.8.jar”被添加到“Referenced Libraries”文件夹下 在代码中,我使用了System.setProperty(“javax.xml.transform.TransformerFactory”、“net.sf.saxon.TransformerFactoryImpl”) 当我尝试调用以下行Trans
replace()
。我在POM文件中添加了对saxon的依赖,并运行了“mvn安装”命令。通过这样做,“saxon-9.1.0.8.jar”被添加到“Referenced Libraries”文件夹下
在代码中,我使用了System.setProperty(“javax.xml.transform.TransformerFactory”、“net.sf.saxon.TransformerFactoryImpl”)代码>
当我尝试调用以下行TransformerFactory.newInstance(“net.sf.saxon.TransformerFactoryImpl”,null)时代码>
我听到一个错误,说
javax.xml.transform.TransformerFactoryConfigurationError: Provider net.sf.saxon.TransformerFactoryImpl not found.
如果我尝试调用new net.sf.saxon.TransformerFactoryImpl()代码>,我得到的错误是java.lang.NoClassDefFoundError:net/sf/saxon/TransformerFactoryImpl
如果我在使用eclipse indigo配置saxon时遗漏了什么,请告诉我。我同意Michael的说法,您没有在类路径中正确包含saxon jar文件。我想eclipse中有一个选项可以通过单击project-build路径-addjar(类似于此)来添加jar文件。尝试一下,构建您的工作区,这可能会有所帮助。我同意Michael的观点,您没有在类路径中正确地包含Saxon jar文件。我想eclipse中有一个选项可以通过单击project-build路径-addjar(类似于此)来添加jar文件。尝试一下,构建您的工作区,这可能会有所帮助。请确保在构建路径中包含了saxon
jar。那么在源代码中,以下几行应该可以工作:
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
TransformerFactory tfactory = TransformerFactory.newInstance();
请确保在构建路径中包含了saxon
jar。那么在源代码中,以下几行应该可以工作:
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
TransformerFactory tfactory = TransformerFactory.newInstance();
下面的简单示例:
确保saxon9ee.jar在类路径中
movie.xml
<?xml version="1.0" encoding="UTF-8"?>
<movies>
<movie>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</movie>
<movie>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</movie>
<movie>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</movie>
<movie>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</movie>
<movie>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</movie>
<movie>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</movie>
</movies>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>Movies</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
<th style="text-align:left">Country</th>
</tr>
<xsl:for-each select="movies/movie">
<xsl:sort select="country"></xsl:sort>
<!-- IF CONDITION -->
<xsl:if test="country='USA'">
<tr>
<td>
<xsl:value-of select="title" />
</td>
<td>
<xsl:value-of select="artist" />
</td>
<td>
<xsl:value-of select="country" />
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
在命令行中运行
C:\Users\ranjiths>java -jar C:\ranjiths\T3\ws\XSLTDemo\lib\saxon9ee.jar C:\ranjiths\T3\ws\XSLTDemo\testdata\xml\movie.xml C:\ranjiths\T3\ws\XSLTDemo\testdata\xsl\movie.xsl
输出:
<html>
<body>
<h2>Movies</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
<th style="text-align:left">Country</th>
</tr>
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
<td>USA</td>
</tr>
<tr>
<td>Greatest Hits</td>
<td>Dolly Parton</td>
<td>USA</td>
</tr>
</table>
</body>
</html>
影视
标题
艺术家
国家
皇帝讽刺剧
鲍勃·迪伦
美国
最成功的
多莉·帕顿
美国
下面的简单示例:
确保saxon9ee.jar在类路径中
movie.xml
<?xml version="1.0" encoding="UTF-8"?>
<movies>
<movie>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</movie>
<movie>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</movie>
<movie>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</movie>
<movie>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</movie>
<movie>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</movie>
<movie>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</movie>
</movies>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>Movies</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
<th style="text-align:left">Country</th>
</tr>
<xsl:for-each select="movies/movie">
<xsl:sort select="country"></xsl:sort>
<!-- IF CONDITION -->
<xsl:if test="country='USA'">
<tr>
<td>
<xsl:value-of select="title" />
</td>
<td>
<xsl:value-of select="artist" />
</td>
<td>
<xsl:value-of select="country" />
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
在命令行中运行
C:\Users\ranjiths>java -jar C:\ranjiths\T3\ws\XSLTDemo\lib\saxon9ee.jar C:\ranjiths\T3\ws\XSLTDemo\testdata\xml\movie.xml C:\ranjiths\T3\ws\XSLTDemo\testdata\xsl\movie.xsl
输出:
<html>
<body>
<h2>Movies</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
<th style="text-align:left">Country</th>
</tr>
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
<td>USA</td>
</tr>
<tr>
<td>Greatest Hits</td>
<td>Dolly Parton</td>
<td>USA</td>
</tr>
</table>
</body>
</html>
影视
标题
艺术家
国家
皇帝讽刺剧
鲍勃·迪伦
美国
最成功的
多莉·帕顿
美国
当您查看jar文件时,它是否显示了类?如果您使用的是Maven,您应该使用Saxon HE。从这里获取最新消息所有消息都表明Saxon jar文件不在类路径上。但是我对配置EclipseIndigo的了解还不够,所以不知道为什么会这样。当您查看jar文件时,它是否显示了类?如果您使用的是Maven,那么应该使用Saxon HE。从这里获取最新消息所有消息都表明Saxon jar文件不在类路径上。但我对配置EclipseIndigo的了解还不够,无法理解为什么会出现这种情况。