This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Re: How to distinguish b/n a scalar and a node-set having a single text node


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]