xsl-list
[Top] [All Lists]

Re: [xsl] Assigning types to variables

2006-09-13 08:24:27
As for the type: I asked a similar question a while back and the general consensus was to not give it a type, as to be explicit and give it a type of document-node() was long-hand for not giving it a type.

When I asked when you should and should not be using an as attribute on xsl:variable in XSLT 2 (27 Feb) I was advised I should always use it!

Given that I do not need to navigate around the element in the manner David suggested I am going to give this an element() type.


From: "andrew welch" <andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Assigning types to variables
Date: Wed, 13 Sep 2006 16:05:22 +0100

On 9/13/06, tom tom <tomxsllist(_at_)hotmail(_dot_)com> wrote:
Hi all, if I have declared the following variable:

<xsl:variable name="test" as="element()">
        <one>
            <two>hello</two>
        </one>
</xsl:variable>

I don't understand why <xsl:sequence select="$test/two"/> retrieves the
value of <two/> while <xsl:sequence select="$test/one/two"/> does not. If I
omit the 'as' attribute it works the other way round. What exactly is
happening when I assign a node() or element() or whatever type to this
variable?

Also could you advise what type I should be using for this kind of task?

It's because you want the variable to be an element, so the variable
$test becomes <one>, so $test/two is the same as one/two, which is why
you get the output you see.

As for the type: I asked a similar question a while back and the
general consensus was to not give it a type, as to be explicit and
give it a type of document-node() was long-hand for not giving it a
type.

I guess my problem is that I'm thinking about variables in XSLT 1 terms!

This is still a grey area for me - the general advice is to give
everything a type, except in this case, it seems.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


_________________________________________________________________
Be the first to hear what's new at MSN - sign up to our free newsletters! http://www.msn.co.uk/newsletters


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>