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

RE: Declarative programming requires a different mindset

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Thu, 25 Mar 2010 07:32:46 -0400

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]


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.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.

Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.