1

I have xsl file when i applied into xml file. And when i viewed it in Internet explorer.I am getting an error as.

Expected token ']' found 'NAME'. threshold[substring-before(normalize-space(), ' ')-->castable <--as xs:integer]

Here is my xsl file.

<xsl:template match="threshold[substring-before(normalize-space(), ' ')castable as xs:integer]">
<xsl:variable name="vNorm" select = "translate(normalize-space(), '%', '')"/>
<xsl:variable name="vAtUnit" select = "substring-after($vNorm, ' ')"/>
<xsl:variable name="vUnit" select ="replace($vAtUnit, '([^0123456789]+)(\d*)', '$1')"/>
<xsl:variable name="vLastPart" as="xs:string" select ="substring-after($vAtUnit, $vUnit)"/>
<xsl:variable name="vNum" select="concat($vLastPart, '100'[not($vLastPart)])"/>
    <threshold>
        <t-r-value><xsl:value-of select="substring-before(., ' ')"/></t-r-value>
        <unit><xsl:value-of select="normalize-space($vUnit)"/></unit>
        <samplepct><xsl:value-of select="$vNum"/></samplepct>
    </threshold>
    <xsl:call-template name="tested"></xsl:call-template>
</xsl:template>
<xsl:template name="tested">
<xsl:for-each select="../following-sibling::interval-repeats[1]/ repeat[ count(current()/preceding-sibling::threshold) + 1]" >
<xsl:variable name="vNormrep" select = "translate(normalize-space(), '%', '')"/>
<xsl:variable name="vAtUnitrep" select = "substring-after($vNormrep, ' ')"/>
<xsl:variable name="vUnitrep" select ="replace($vAtUnitrep, '([^0123456789]+)(\d*)', '$1')"/>
<xsl:variable name="vLastPart" as="xs:string" select ="substring-after($vAtUnitrep, $vUnitrep)"/>
<xsl:variable name="vNumrep" select="concat($vLastPart, '100'[not($vLastPart)])"/>
    <repeat>
        <t-r-value><xsl:value-of select="substring-before(., ' ')"/></t-r-value>
        <unit><xsl:value-of select="normalize-space($vUnitrep)"/></unit>
        <samplepct><xsl:value-of select="$vNumrep"/></samplepct>
    </repeat>
</xsl:for-each>

Can any one help me here pls.

Thanks in advance Karthic

karthic
  • 175
  • 1
  • 1
  • 9

2 Answers2

2

Browsers only support XSLT 1.0 plus some EXSLT extensions, if you want to use XSLT 2.0 you need to use an XSLT 2.0 processor like Saxon 9, AltovaXML or XmlPrime. If you want to use XSLT 2.0 client-side you can check whether Saxon CE http://www.saxonica.com/ce/download.xml is an option.

[edit] As for trying to implement the integer check in XSLT 1.0 you could try

<xsl:template match="threshold[not(translate(substring-before(normalize-space(), ' '), '0123456789', ''))]">

That check removes any digits and then checks whether the result is an empty string which might suffice to check for an integer

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
1

One short XPath expression to verify if a string is castable to an integer is:

$x = floor($x)

As already noted in another answer, none of the major five browsers supports XSLT 2.0. A way at present to use XSLT 2.0 in the browser is provided by Saxon CE.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431