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

Re: Re: How to distinguish b/n a scalar and a node-set havin

Subject: Re: Re: How to distinguish b/n a scalar and a node-set having a single text node
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 24 Oct 2000 13:03:22 -0400 (EST)
msxsl node set child nodes
Mike Brown wrote:
>Dimitre Novatchev wrote:
>> I am trying to determine whether the value of a parameter is a
scalar
>> or a node-set, and to do so without using extension functions (I
>> consider node-set() to be "standard", as it will be in XSLT 1.1).
>> 
>> The only problemetic case is:
>> How to determine whether what seems to be a node-set having a single
>> text node is actually a node set or whether it is a scalar (the
value
>> of the text node).
>

>A parameter is going to be one of the 4 object types in XPath:
boolean,
>number, string, node-set, or the object type introduced in XSLT:
result
>tree fragment. There is no concept of 'scalar'.
>
>I don't think there is a way to test for the type of object. The few
>operations that are permissible on any type of object do not provide
>helpful info. 
>
>   - Mike

OK, I should have been more precise:

1. By scalar I mean boolean or number or string.

2. I know in advance that in the case I'm interested in, the parameter
will not contain a RTF. Therefore, I need to determine whether the
value contained is a node-set or not.

3. The following (simplified just to convey the idea) template, when
called with any parameter named $pValue, will determine whether the
parameter's value contains nodes that are not text nodes. In a similar
way it finds namespace nodes (different from the default xml namespace
node) and attribute nodes.

<xsl:template name="isNode-Set">
  <xsl:param name="pValue"/>

  <xsl:variable name="vContainer">
    <xsl:element name="body">
      <xsl:copy-of select="$pValue"/>
    </xsl:element>
  </xsl:variable>

<!-- <xsl:copy-of select="$vContainer"/> -->

  <xsl:choose>
    <xsl:when test="count(msxsl:node-set($vContainer)/body/node()[* or
comment() or processing-instruction()]) > 0">
      <xsl:text>Node-Set</xsl:text>
    </xsl:when>
    <xsl:when
test="count(msxsl:node-set($vContainer)/body/namespace::*[. !=
$defaultXMLNamespace]) > 0">
      <xsl:text>Node-Set</xsl:text>
    </xsl:when>
    <xsl:when test="count(msxsl:node-set($vContainer)/body/@*) > 0">
      <xsl:text>Node-Set</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>Scalar</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

When called for example with the following param values: /, count(/*)

it produces accordingly:
Node-Set, Scalar.

4. If $pValue contains a node-set of more than one text nodes, then the
string-length(string(msxsl:node-set($vContainer)/body)) will be
different from string-length($pValue). The first will return the total
length of all text nodes (all child nodes of the "body" element). The
second will return the string length of just the first text node in
$pValue. Therefore this test can be added to the above template to
cover this case.

5. The only unsolved case remains when $pValue contains exactly one
text node.  In this case the comparison in 4. above will return
equality and it could not be decided whether $pValue contains "just
text" or is a nodeset consisting of a single text node. This was my
original question to this mailing list.

I hope that now my original question can be better understood.

Once again, I'd appreciate any help and suggestions.

Cheers,
Dimitre Novatchev.


__________________________________________________
Do You Yahoo!?
Yahoo! Messenger - Talk while you surf!  It's FREE.
http://im.yahoo.com/




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.