2014-02-14 60 views
-1

我试图编译XSLT 1.0样式的孩子,正在此错误: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="'&quot;'" /> 
      <xsl:with-param name="with" select="'\&quot;'"/> 
     </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> 

回答

5

的应用模板标签无法正常关闭: 不当:

<xsl:apply-templates select="time_stamp/*"> 

正确:

<xsl:apply-templates select="time_stamp/*"/> 
相关问题