title: XSLT 1.0: The 'select' expression did not evaluate to a node set
body: <p>When applying my XSLT 1.0 stylesheets, I am receiving the following error:</p>
  
  <pre><code>#&lt;RuntimeError: runtime error: element apply-templates
  The 'select' expression did not evaluate to a node set.
  </code></pre>
  
  <p>Not entirely sure where/why this is happening. Here is my stylesheet as-is using XSLT 1.0:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" /&gt;
  
    &lt;xsl:template match="/message"&gt;
    {
      "heading": "&lt;xsl:apply-templates select="normalize-space(heading/text())"/&gt;",
      "note_id": &lt;xsl:apply-templates select="number(NoteID)"/&gt;,
      "player_id": &lt;xsl:apply-templates select="number(PlayerID)"/&gt;,
      "team_id": &lt;xsl:apply-templates select="number(TeamID)"/&gt;,
      "first_name": "&lt;xsl:apply-templates select="normalize-space(Firstname/text())"/&gt;",
      "last_name": "&lt;xsl:apply-templates select="normalize-space(Lastname/text())"/&gt;",
      "position": "&lt;xsl:apply-templates select="normalize-space(Position/text())"/&gt;",
      "hot_cold": "&lt;xsl:apply-templates select="normalize-space(HotCold/text())"/&gt;",
      "status": "&lt;xsl:apply-templates select="normalize-space(Status/text())"/&gt;",
      "description": "&lt;xsl:apply-templates select="Description/*"/&gt;",
      "insight": "&lt;xsl:apply-templates select="Insight/*"/&gt;",
      "timestamp": "&lt;xsl:apply-templates select="time_stamp/*"/&gt;"
    }
  
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*"&gt;
        &lt;xsl:copy&gt;
            &lt;xsl:apply-templates/&gt;
        &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="text()"&gt;
    &lt;xsl:variable name="escaped-text"&gt;
        &lt;xsl:call-template name="replace-string"&gt;
            &lt;xsl:with-param name="text" select="."/&gt;
            &lt;xsl:with-param name="replace" select="'&amp;quot;'" /&gt;
            &lt;xsl:with-param name="with" select="'\&amp;quot;'"/&gt;
        &lt;/xsl:call-template&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:value-of select="normalize-space($escaped-text)"/&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template name="replace-string"&gt;
        &lt;xsl:param name="text"/&gt;
        &lt;xsl:param name="replace"/&gt;
        &lt;xsl:param name="with"/&gt;
        &lt;xsl:choose&gt;
            &lt;xsl:when test="contains($text,$replace)"&gt;
                &lt;xsl:value-of select="substring-before($text,$replace)"/&gt;
                &lt;xsl:value-of select="$with"/&gt;
                &lt;xsl:call-template name="replace-string"&gt;
                    &lt;xsl:with-param name="text"
                        select="substring-after($text,$replace)"/&gt;
                    &lt;xsl:with-param name="replace" select="$replace"/&gt;
                    &lt;xsl:with-param name="with" select="$with"/&gt;
                &lt;/xsl:call-template&gt;
            &lt;/xsl:when&gt;
            &lt;xsl:otherwise&gt;
                &lt;xsl:value-of select="$text"/&gt;
            &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>here is sample XML, I am simply trying to escape double quotes and retain any <code>&lt;P&gt;</code> tags if and when they exist in the <code>&lt;Description&gt;</code> and <code>&lt;Insight&gt;</code> tags. This particular example doesn't have to deal with that.</p>
  
  <pre><code>&lt;?xml version="1.0" standalone="no" ?&gt;
  &lt;!-- &lt;!DOCTYPE message PUBLIC "-//TSN//DTD News 1.0/EN" "PlayerNotes.dtd"&gt; --&gt;
  &lt;message&gt;
  &lt;XML_File_ID&gt;64166.194&lt;/XML_File_ID&gt;
  &lt;heading&gt;FHB;PNOTES-YASIEL-PUIG&lt;/heading&gt;
  &lt;category&gt;MLB Fantasy Sports&lt;/category&gt;
  &lt;sport&gt;MLB&lt;/sport&gt;
  &lt;NoteID&gt;104585&lt;/NoteID&gt;
  &lt;PlayerID&gt;22526&lt;/PlayerID&gt;
  &lt;TeamID&gt;005&lt;/TeamID&gt;
  &lt;Firstname&gt;Yasiel&lt;/Firstname&gt;
  &lt;Lastname&gt;Puig&lt;/Lastname&gt;
  &lt;Position&gt;RF&lt;/Position&gt;
  &lt;HotCold&gt;&lt;/HotCold&gt;
  &lt;Status&gt;&lt;/Status&gt;
  &lt;Description&gt;The Dodgers have limited outfielder Yasiel Puig's throwing due to right shoulder inflammation, according to mlb.com.&lt;/Description&gt;
  &lt;Insight&gt;Puig (.319, 19 HR, 42 RBI, 11 SB) dealt with the same issue sporadically last season and it flared up again when he overextended himself during his first day of camp. "We don't think it's serious, but we need to find out," manager Don Mattingly said.&lt;/Insight&gt;
  &lt;time_stamp&gt;February 14, 2014, at 08:52 AM ET&lt;/time_stamp&gt;
  &lt;/message&gt; 
  </code></pre>