XSLT找不到根元素(如果其中有连字符):
<serial-issue>
<title>hello</title>
<issue-info>
<pii>3426-4114(11)X6013-4</pii>
<jid>Journal</jid>
<issn>1526-4114</issn>
</issue-info>
</serial-issue>
下面是XSLT脚本:
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="serial-issue"/>
</body>
</html>
</xsl:template>
<xsl:template match="issue-info">
<test>
<xsl:value-of select="jid"/>
</test>
</xsl:template>
上面的脚本不起作用。如果将"serial issue"更改为"serialissue",则会起作用。你能帮忙吗?
在本例中,调用了一个匹配"serial issue"的模板,但没有这样的模板。
添加
<xsl:template match="serial-issue">
<xsl:apply-templates />
</xsl:template>
到XSL脚本将解决这个问题。此外,它不是HTML标记,因此在输出中不会起作用。
样式表的最小版本可能如下所示:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html><body>
<xsl:apply-templates />
</body></html>
</xsl:template>
<xsl:template match="serial-issue">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="issue-info">
<xsl:value-of select="jid"/>
</xsl:template>
</xsl:stylesheet>