Re: count() woes

Subject: Re: count() woes
From: Natalie Rooney <nrooney@xxxxxxxxxxxxx>
Date: Fri, 12 Nov 1999 10:43:28 -0600
Okay, I must apologize again for being vague again.  Of course, all of
this stuff seems very clear to me because
I've been struggling with it for quite awhile.  Let me try this again:

Clark:   By the way, the <FIRST></FIR-ST> was a copying mistake.  The xml
is fine, and the page gets processed
into html using XSL:P.

As you can see in the xml below, I have 3 BADUSER elements.  What I want
to do is select the child nodes of each one of these BADUSER elements
individually.  So, I would think that I should use:        (assume
$tagName = FIRST)

<xsl:value-of select="//BADUSERS/BADUSER[2]/*[ name() = $tagname ]"/>

to select th FIRST child of the second BADUSER node.  But, this returns
nothing in the html output.

So, that is why I was messing around with parentheses and count()
statements, so I could see what was going on.
That is when I got this behavior:



Weird Behavior:

<xsl:value-of select="count( //BADUSERS/BADUSER[2]/* )"/>
returns 0 - (finds no child elements of the second BADUSER)

<xsl:value-of select="count( //BADUSERS/BADUSER[2] )"/>
returns 0 - (finds no second BADUSER)

<xsl:value-of select="count( //BADUSERS/BADUSER[1])"/>
returns 3 - (finds 3 BADUSER elements who are the first child node of
BADUSERS)


These last two (below) are really strange with the parentheses, because
the first statement
seems to correctly select only one of the BADUSER nodes, but the second
statement returns
0 when the second BADUSER node clearly has children.

<xsl:value-of select="count( (//BADUSERS/BADUSER)[2] )"/>
returns 1

<xsl:value-of select="count( (//BADUSERS/BADUSER)[2]/* )"/>
returns nothing





I also have this statement in the xsl stylesheet:

<xsl:apply-templates select="//BADUSERS/BADUSER[2]/*[ name() = $tagname
]/@score"/>
(and I made a template that matches "@score")

This returns  the score attribute of the FIRST element of all three
BADUSER's.  But this works as
expected (when parentheses are included):

<xsl:apply-templates select="(//BADUSERS/BADUSER)[2]/*[ name() = $tagname
]/@score"/>

That is, it returns the score attribute of the FIRST child of the second
BADUSER node.


This stuff is all pretty confusing and difficult to explain, so I hope
this is semi-clear.  I am positive that
my XML is fine ( if it weren't, it wouldn't be processed through XSL:P
).  Also, I am pretty confident that my logic
is correct here which is why I don't understand what is going on.

Things that work a certain way in xsl:apply-templates select statements
don't work the same way in xsl:value-of
select statements.

Please help.

Thanks,
Natalie

P.S.  The xml is automatically generated inside a servlet and  I call

    PrintWriter out = res.getWriter();
    XSLProcessor xslp = new XSLProcessor;
    xslp.process( xmlInputStream, xslInputStream, out );

    Don't know if that should make any difference or not.


____________________________________________________________________

I have removed the values of the attributes, but here is the xml
structure:


  <?xml version="1.0" ?>
- <RESULTS>

- <DISPLAYNAMES>
  <USERID>User ID</USERID>
  <LAST>Last Name</LAST>
  <FIRST>First Name</FIRST>
  <EMAIL>Email</EMAIL>
  <GEO_REGION>Zip Code</GEO_REGION>
  <STATE>State</STATE>
  <CITY>City</CITY>
  <ADDRESS>Address</ADDRESS>
  <SEX>Gender</SEX>
  <PASSWORD>Password</PASSWORD>
  <CREDIT_CARD>Credit Card</CREDIT_CARD>
  </DISPLAYNAMES>

 <NEWUSER>
  <USERID></USERID>
  <LAS ></LAST>
  <FIRST></FIRST>
  <EMAIL></EMAIL>
  <GEO_REGION></GEO_REGION>
  <STATE></STATE>
  <CITY></CITY>
  <ADDRESS></ADDRESS>
  <SEX></SEX>
  <PASSWORD></PASSWORD>
  <CREDIT_CARD></CREDIT_CARD>
  </NEWUSER>

<BADUSERS>
 <BADUSER>
  <USERID></USERID>
  <LAS ></LAST>
  <FIRST></FIRST>
  <EMAIL></EMAIL>
  <GEO_REGION></GEO_REGION>
  <STATE></STATE>
  <CITY></CITY>
  <ADDRESS></ADDRESS>
  <SEX></SEX>
  <PASSWORD></PASSWORD>
  <CREDIT_CARD></CREDIT_CARD>
  </BADUSER>

 <BADUSER>
  <USERID></USERID>
  <LAS ></LAST>
  <FIRST></FIRST>
  <EMAIL></EMAIL>
  <GEO_REGION></GEO_REGION>
  <STATE></STATE>
  <CITY></CITY>
  <ADDRESS></ADDRESS>
  <SEX></SEX>
  <PASSWORD></PASSWORD>
  <CREDIT_CARD></CREDIT_CARD>
  </BADUSER>

 <BADUSER>
  <USERID></USERID>
  <LAS ></LAST>
  <FIRST></FIRST>
  <EMAIL></EMAIL>
  <GEO_REGION></GEO_REGION>
  <STATE></STATE>
  <CITY></CITY>
  <ADDRESS></ADDRESS>
  <SEX></SEX>
  <PASSWORD></PASSWORD>
  <CREDIT_CARD></CREDIT_CARD>
  </BADUSER>
</BADUSERS>

  </RESULTS>







"Clark C. Evans" wrote:

> Natalie,
>
> I'm still not sure what you are trying to
> accomplish and why you are using parentheses
> in the xpath expressions.
>
> Clark
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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


Current Thread