我在嘗試轉換以下HTML代碼,但遇到了獲取所需值以及使用XSLT的子字符串函數的問題。這是我想改變的HTML代碼的一部分:將HTML轉換爲XML的XSLT
<th scope="row">2005DEC</th>
<td>2,757</td>
以下XML代碼:
<?xml version="1.0"?>
<Original>
<Entry>
<Year>2005</Year>
<Month>DEC</Month>
<Age>
<Group>
<value>90</value>
</Group>
</Age>
</Entry>
</Original>
我試圖運行XSLT查詢,但它一直得到一個錯誤。我的XSLT是:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<Original>
<xsl:for-each select="@scope=row">
<Entry>
<Year>
<xsl:value-of select="substring(@scope=row, 1, 4)"/>
</Year>
<Month>
<xsl:value-of select="substring(@scope=row, 5, 3)"/>
</Month>
<Age>
<Group>
<value>
<xsl:value-of select="td[1]"/>
</value>
</Group>
</Age>
</Entry>
</xsl:for-each>
</Original>
</xsl:template>
</xsl:stylesheet>
的錯誤是:
Ivans-MacBook-Pro:xslt-test ivanteong$ java -jar saxon9he.jar table823.html table823.xslt > out.xml
Error at xsl:value-of on line 13 column 73 of table823.xslt:
XPTY0004: Required item type of first argument of substring() is xs:string; supplied value
has item type xs:boolean
Error at xsl:value-of on line 16 column 73 of table823.xslt:
XPTY0004: Required item type of first argument of substring() is xs:string; supplied value
has item type xs:boolean
Failed to compile stylesheet. 2 errors detected.
請仔細閱讀:[MCVE] –