Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2004, 10:34 AM
Registered User
 
Join Date: Jun 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Determining the number of children

How can i determine the number of children, which nodename starts with a certain string, e.g. "level"?
 
Old November 30th, 2004, 10:48 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Use the starts-with function, e.g. this gives you all children of the context node that start with "level":
Code:
<xsl:apply-templates select="*[starts-with(name(), 'level')]"/>
this gives you all descendants of the context node that start with "level":
Code:
<xsl:apply-templates select=".//*[starts-with(name(), 'level')]"/>
If you are using namespaces then replace name() with local-name().



--

Joe (Microsoft MVP - XML)
 
Old November 30th, 2004, 10:50 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am guessing that by saying "nodename starts with", your xml may look like this:

  <levels>
    <level1></level1>
    <level2></level2>
    <level3></level3>
    <leveln></leveln>
  </levels>

If context is "levels" :

  <xsl:value-of select="count(*[starts-with(name(), 'level')])" />

If namespaces are involved you might want to use the local-name() function instead.

Regards
Bryan






Similar Threads
Thread Thread Starter Forum Replies Last Post
help with nodes/children bmmayer XML 0 July 13th, 2007 05:04 PM
MDI Children angelboy C# 2005 5 June 28th, 2007 06:08 AM
match only first level children sgruhier XSLT 1 February 22nd, 2005 05:12 AM
Determining page number of a range name santon198 Excel VBA 0 May 10th, 2004 01:20 AM
get all children nodes maratg XSLT 4 November 7th, 2003 02:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.