OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: Declarative programming requires a different mindset

Hi Folks,


Yesterday’s responses were outstanding and illuminating. Thank you.


I learned that a declarative program describes the relationship of the output to the input.


This raises new questions. Let’s take an example. Suppose that this is the input:




I want the output to contain the URL and the filename separated:







This XSLT code describes the relationship of the output to the input:


<xsl:template match="XML-file">

    <xsl:variable name="url"

                  select="f:substring-before-last(., '/')" />



            <xsl:value-of select="$url" />



            <xsl:value-of select="substring-after(., $url)" />





I believe this code is declarative. Do you agree?


Note my use of the function, f:substring-before-last(). There is no such built-in function, I created it. Below is how I implemented it. The implementation doesn’t seem descriptive. It seems quite recipe-like:


   Get the substring before $delimiter and output it,

   then output $delimiter, and then recurse.


It seems quite imperative. Do you agree?


If I stuff a bunch of imperative code into functions, and the “main” code is declarative, do I still have a declarative program?


Here’s my implementation of f:substring-before-last():


<xsl:function name="f:substring-before-last" as="xs:string?">

    <xsl:param name="string" as="xs:string" />

    <xsl:param name="delimiter" as="xs:string" />


    <xsl:if test="contains( $string, $delimiter )">

        <xsl:variable name="url">


               select="substring-before( $string, $delimiter )"/>

            <xsl:value-of select="$delimiter"/>



                        ( $string, $delimiter ), $delimiter)" />


        <xsl:value-of select="$url" />





[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS