[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Confusion with the results of starts-with() and a

Subject: Re: Confusion with the results of starts-with() and a non-string arg
From: "Bridger Dyson-Smith bdysonsmith@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 Dec 2018 21:23:04 -0000
Re:  Confusion with the results of starts-with() and a
Michael -

On Wed, Dec 12, 2018 at 4:20 PM Michael Kay mike@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> true here means child::true, a reference to an element node. It's not the
> boolean constant true(). Saxon will generally give you a warning about this.
>
> You don't have an element named true, therefore child::true returns an
> empty sequence, and functions like starts-with treat an empty sequence the
> same as an empty string. Every string starts with the empty string, so the
> function returns true - or rather, true().
>
> Perfect - the child::true -> empty sequence -> empty string is exactly the
explanation that I needed.


> Michael Kay
> Saxonica
>
> Thanks!
Bridger

On 12 Dec 2018, at 21:10, Bridger Dyson-Smith bdysonsmith@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> 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/293509> (by
> email)
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/1230532> (by
> email <>)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.