0

I have an example of an XSLT transform which tests if a given value is contained in a list of values. The syntax is as follows:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>

    <xsl:template match="field">
        <FIELD>
            <xsl:choose>
                <xsl:when test="current() = ('v1', 'val1')">
                    YES
                </xsl:when>
                <xsl:when test="current() = ('v2', 'val2')">
                    NO
                </xsl:when>
                <xsl:otherwise>
                    UNKNOWN
                </xsl:otherwise>
            </xsl:choose>
        </FIELD>
    </xsl:template>

</xsl:stylesheet>    

The test XML:

<?xml version="1.0" encoding="iso-8859-1"?>
<doc>
    <field>v1</field>
    <field>val2</field>
    <field>v3</field>
</doc>

The online XSLT testing tool is processing that correctly, but for example, IntelliJ, is screaming:

[ERROR]: Syntax error in 'current() = ('v1', 'val1')'

I have problems to find examples of this particular syntax on the internet in standard XSLT tutorials as well as on StackOverflow, using phrases like (xslt set syntax), (xslt value in) etc.

Is that syntax correct and standard-compliant, or some semi-official extension?

zx485
  • 28,498
  • 28
  • 50
  • 59
9ilsdx 9rvj 0lo
  • 7,955
  • 10
  • 38
  • 77

1 Answers1

1

What you show is XSLT 2.0 syntax, and the error is most likely caused by running this with an XSLT 1.0 processor.

You can use:

<xsl:value-of select="system-property('xsl:version')"/> 

to check which XSLT version your processor supports.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Thanks. It looks like IntelliJ is using XSLT version 1.0. But nevertheless, if my syntax is a part of 2.0, why it's so hard to find examples using it? – 9ilsdx 9rvj 0lo May 12 '16 at 14:50
  • @9ilsdx9rvj0lo You can find examples right in the spec: https://www.w3.org/TR/xpath20/#id-general-comparisons Or do a search for "sequence comparison". Here's one I found very quickly: http://stackoverflow.com/a/6357859/3016153 – michael.hor257k May 12 '16 at 14:56
  • the key is the phrase 'sequence comparison' which I haven't used in my search, it looks like my question is simply a duplicate. – 9ilsdx 9rvj 0lo May 12 '16 at 15:01