xslt - Substring before throwing error -


i've below xml

<?xml version="1.0" encoding="utf-8"?> <body>  <p>industrial drawing: creative composition</p>    <p>industrial drawing: creative<fn>           <fnn>4</fnn>           <fnt>             <p>ftn1"</p>           </fnt>         </fn> composition       </p> </body> 

and below xsl.

<xsl:template match="p">     <xsl:choose>         <xsl:when test="contains(substring-before(./text(),' '),'article')">             <xsl:text>sect3</xsl:text>             <xsl:value-of select="./text()"/>         </xsl:when>         <xsl:when test="contains(substring-before(./b/text(),' '),'section')">             <xsl:text> sect 2</xsl:text>             <xsl:value-of select="./text()"/>         </xsl:when>         <xsl:when test="contains(substring-before(./b/text(),' '),'chapter')">             <xsl:text> sect 1</xsl:text>             <xsl:value-of select="./text()"/>         </xsl:when>         <xsl:otherwise>  </xsl:otherwise>     </xsl:choose> </xsl:template> 

here xsl working fine <p>industrial drawing: creative composition</p> below case

 <p>industrial drawing: creative<fn>       <fnn>4</fnn>          <fnt>             <p>ftn1"</p>          </fnt>       </fn> composition  </p> 

it throwing me below error.

xslt 2.0 debugging error: error: file:///c:/users/u0138039/desktop/proview/asak/difc/xslt/tabel.xslt:38: wrong occurrence match required sequence type -   details: -     xpty0004: supplied sequence ('2' item(s)) has wrong occurrence match sequence type xs:string ('zero or one') 

please let me know how can fix , grab text required.

thanks

the p element in example has several text nodes, expression ./text() creates sequence. cannot apply string function sequence; must convert string first. instead of:

test="contains(substring-before(./text(),' '),'article')" 

try:

test="contains(substring-before(string-join(text(), ''), ' '), 'article')" 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -