Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT Child Node Count Problem 1

Status
Not open for further replies.

TheVillageIdiot27

Programmer
Nov 10, 2005
58
GB
Hi

I haven't used XSLT for ages so apologies for this...

I have an XML document created by a database which maps out files and folders i.e.
Code:
<root>
	<folder name=”folder 1”>
		<file name=”file 1”>
		<file name=”file 2”>
	</folder>
	<folder name=”folder 2”>
		<folder name=”folder 2a”>
			<file name=”file 3”>
		</folder>
	</folder>
	<folder name=”folder 3”>
		<folder name=”folder 3a” />
	</folder>
</root>
I am applying an XSL Transform to this but as part of this I need to make that somewhere beneath the current folder node is at least one file node – no matter how many levels beneath it is (i.e. entirely exclude "<folder name='3'>"). In addition I also need to count the file nodes and output that but I guess this is the same problem.

I am sure it’s something like
<xsl:if test="count([something]file) &gt; 0"> and
<xsl:value-of select="[something]count(file)"/>
but can’t seem to get it quite right
 
Suppose some folder element is the context node.

><xsl:if test="count([something]file) &gt; 0">
[tt]<xsl:if test="count(.//file) &gt; 0">[/tt]

><xsl:value-of select="[something]count(file)"/>
[tt]<xsl:value-of select="count(.//file)"/>[/tt]

ps: your sample as such is not well-formed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top