473,385 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

count(parent)

Hi,

I would like to add an attribute to the child node if it is the only child
node. The problem is I am not getting the correct count of child nodes with
this template:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:if test="name()='par' and count(parent::node()) = 1">
<xsl:attribute name="repeatCount">
<xsl:text>1</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Here, the 'par' node is the current child node and I would like to check
something like: if parent node of the current 'par' node has only one 'par'
node then add 'repeatCount' attribute to the only 'par' child node. But the
condition
<xsl:if test="name()='par' and count(parent::node()) = 1"> does not work for
me. What am I doing wrong in this condition?

Btw, I am using Xalan.

Thx, in advance!
Jul 20 '05 #1
2 3305
Tempore 20:01:16, die Thursday 13 January 2005 AD, hinc in foro {comp.text.xml} scripsit Nutshell <sa*********@mail.htnet.hr>:
Here, the 'par' node is the current child node and I would like to check
something like: if parent node of the current 'par' node has only one 'par'
node then add 'repeatCount' attribute to the only 'par' child node.


Hi,

The test expression could be something like this:
<xsl:if test="self::par and count(../par) = 1">
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
Jul 20 '05 #2
> <xsl:if test="name()='par' and count(parent::node()) = 1"> does not work for
me. What am I doing wrong in this condition?


'parent::node()' (abbreviated '..') selects all parent nodes of the context node. Since all nodes (all descendants of the document root) have exactly 1 parent, the test 'count(parent::node()) = 1' will always return true.

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML:...
3
by: rob.guitar.rob | last post by:
Hello, My last few posts have been revolving aroung the same problem, and I still cant solve it and I would be really appreciate if anyone could spot a problem. a section of my XML goes like...
2
by: jonsjostedt | last post by:
Hello all! What is a neat way to count the number of children for every parent in code below? CREATE TABLE parent ( row_id INTEGER NOT NULL IDENTITY(1,1)
3
by: sergey | last post by:
Hi, I want show all components names on form when I press button. I wrote this code button's.onclick event: for (int i = 0; i<=this.components.Components.count - 1; i++)...
4
by: Danny Tuppeny | last post by:
Hi all, I've been trying to write some classes, so when I have a parent-child relationship, such as with Folders in my application, I don't have to remember to add a parent reference, as well as...
1
by: mad_a | last post by:
I have a question about XSLT. I am trying to count the number of sibblings a parent node has (of a specific name). Say I have <topNode> <page> text in here</page> <page> text in...
0
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
0
by: alivip | last post by:
Is python provide search in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name camry and file name corola,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.