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

RE: count() woes

Subject: RE: count() woes
From: Mark Hayes <mark@xxxxxxxxxxx>
Date: Sat, 13 Nov 1999 13:14:51 -0800
xsl tagname value
It is best to try to reduce the problem to a small set of XML and XSL that
you can use to test a specific case.  I've tried to do this below and the
output looks correct.  However, I'm using the current version of XT, and
this may not be exactly what you're trying to do.  But I did copy your
<xsl:value-of> tag verbatim.

<!-- XML SOURCE -->
<BADUSERS>
  <BADUSER>
    <FIRST>one</FIRST>
  </BADUSER>
  <BADUSER>
    <FIRST>two</FIRST>
  </BADUSER>
  <BADUSER>
    <FIRST>three</FIRST>
  </BADUSER>
</BADUSERS>

<!-- STYLESHEET -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:template match="/">
    <xsl:variable name="tagname" select="'FIRST'"/>
    <xsl:value-of select="//BADUSERS/BADUSER[2]/*[ name() = $tagname ]"/>
  </xsl:template>
</xsl:stylesheet>

<!-- XML RESULT -->
<?xml version="1.0" encoding="utf-8"?>
two

Hope this helps.
--
mark

> -----Original Message-----
> From: Natalie Rooney [mailto:nrooney@xxxxxxxxxxxxx]
> Sent: Friday, November 12, 1999 8:43 AM
> To: xsl-list@xxxxxxxxxxxxxxxx
> Subject: Re: count() woes
> 
> 
> 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


 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.