xsl-list
[Top] [All Lists]

[xsl] Confusion with the results of starts-with() and a non-string arg

2018-12-12 15:10:05
Hi all -

In the process of trying to illustrate something for a coworker, I stumbled
across some behavior that has me Very Confused. I would expect the
starts-with function to return 'false' when the second argument is not a
string, but the opposite happens: it returns 'true'.

Can someone please help me understand what's happening here? Is this a sort
of type casting, or something else?

Thank you in advance.
Best,
Bridger

source.xml
```
<?xml version="1.0" encoding="UTF-8"?>
<test>
  <my-string>This Is My String</my-string>
</test>
```

test.xsl
```
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
  exclude-result-prefixes="xs"
  version="2.0">

  <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="my-string">
    <xsl:if test="starts-with(.,true)">
      <my-string-true>
        <xsl:value-of select="starts-with(.,true)"/>
        <xsl:text>###</xsl:text>
        <xsl:value-of select="starts-with(.,'no')"/>
      </my-string-true>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
```
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>