EnexoOnoma
EnexoOnoma

Reputation: 8836

Error with substring in XSLT

I was wondering if XSLT has the option to delete the content of an element if the chars are more than 200. Below I make use of all the content element.

Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: runtime error: file stylesheet.xslt line 42 element apply-templates in index.php on line 20

Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: The 'select' expression did not evaluate to a node set. in index.php on line 20

<xsl:template match="a:content | description">
  <c>
        <xsl:apply-templates select="substring('node() | @*', 1, 200)" />
  </c>
</xsl:template>

Upvotes: 0

Views: 492

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243529

<xsl:apply-templates select="substring('node() | @*', 1, 200)" />

The Xpath expression specified in the select attribute above, is of type xs:string.

However, in XSLT 1.0 and XSLT 2.0 templates can only be applied on nodes -- not on strings. This is why you get the reported error message.

It seems to me that what you most probably want is:

<xsl:value-of select="substring(., 1, 200)" />

Upvotes: 1

Related Questions