0
我想用XSL和groovy轉換一些XML。我爲它使用javax.xml.transform.TransformerFactory。詞法比較的問題
但是在我的XLS文件中比較並不像我想象的那樣工作。
它不能告訴我,2.0.1大於2.0。爲什麼?我認爲這應該是因爲xsl:stylesheet version =「2.0」。我做錯了什麼?
這裏是我的文件:
XML
<?xml version="1.0" encoding="UTF-8"?>
<apis>
<api version="2.0.1">
<resource>
<description>doc for API 2.0.1</description>
</resource>
</api>
</apis>
XSL
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="api-version" select="2.0"/>
<xsl:template match="/apis/api[@version > $api-version]/resource">
<resource>
<xsl:value-of select="description"></xsl:value-of>
</resource>
</xsl:template>
</xsl:stylesheet>
和Groovy腳本
import javax.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource
def workspacePath
def xslPath
def xslFileName
def xmlPath
def xmlFileName
def outputPath
def outputFileName
def xslt
def transformer
def xml
def output
def apiVersions
workspacePath = "C:/test/"
xslPath = "transformations/"
xslFileName = "test5.xsl"
xmlPath = "pendingFeature/"
xmlFileName = "test5.xml"
outputPath = "outputs/"
xslt = new File(workspacePath + xslPath + xslFileName).getText()
transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(xslt)))
xml = new File(workspacePath + xmlPath + xmlFileName).getText()
outputFileName = "doc.html"
output = new FileOutputStream(workspacePath + outputPath + outputFileName)
transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(output))
output.close()