简体   繁体   中英

XSLT 1.0: element template only allowed as child of stylesheet

I am attempting to compile an XSLT 1.0 stylesheets and am getting this error:

#<RuntimeError: compilation error: element template
element template only allowed as child of stylesheet

The error seems like an obvious fix, but there's no indication in my stylesheet markup that any template element's are using are not a child of stylesheet . Below is my entire template:

<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>

the apply-templates tag isn't closed properly: improper:

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

proper:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM