我正在尝试编译XSLT 1.0样式表并收到此错误:
#<RuntimeError: compilation error: element template
element template only allowed as child of stylesheet
错误似乎是一个明显的修复,但我的样式表标记中没有迹象表明任何template
元素正在使用的不是child of stylesheet
。以下是我的整个模板:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" />
<xsl:template match="/message">
{
"heading": "<xsl:apply-templates select="normalize-space(heading/text())"/>",
"note_id": <xsl:apply-templates select="number(NoteID)"/>,
"player_id": <xsl:apply-templates select="number(PlayerID)"/>,
"team_id": <xsl:apply-templates select="number(TeamID)"/>,
"first_name": "<xsl:apply-templates select="normalize-space(Firstname/text())"/>",
"last_name": "<xsl:apply-templates select="normalize-space(Lastname/text())"/>",
"position": "<xsl:apply-templates select="normalize-space(Position/text())"/>",
"hot_cold": "<xsl:apply-templates select="normalize-space(HotCold/text())"/>",
"status": "<xsl:apply-templates select="normalize-space(Status/text())"/>",
"description": "<xsl:apply-templates select="Description/*"/>",
"insight": "<xsl:apply-templates select="Insight/*"/>",
"timestamp": "<xsl:apply-templates select="time_stamp/*">"
}
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:variable name="escaped-text">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="replace" select="'"'" />
<xsl:with-param name="with" select="'\"'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="normalize-space($escaped-text)"/>
</xsl:template>
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text"
select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:5)
apply-templates标签未正确关闭: 不当:
<xsl:apply-templates select="time_stamp/*">
正确:
<xsl:apply-templates select="time_stamp/*"/>