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

RE: Count number of specific child templates

Subject: RE: Count number of specific child templates
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 7 Apr 2009 09:15:49 +0100
RE:  Count number of specific child templates
What should the result be if <parameters> contains 2 <service1> children and
5 <service2> children?

If the answer is 7, then perhaps you want

count(*[starts-with(local-name(), 'service')])

Generally it looks like bad XML design to have some semantic significance
implied by the fact that <service1> and <service2> have similar names.
Better design would be to use <service nr="1"> and <service nr="2">.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: himanshu padmanabhi [mailto:himanshu.padmanabhi@xxxxxxxxx] 
> Sent: 07 April 2009 08:44
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Count number of specific child templates
> 
> Case 1
> 
> <?xml version='1.0'?>
> <?xml-stylesheet href="service1.xsl" type="text/xsl"?>
> 
> <parameters>
>     <service1>
>           <label>first parameter</label>
>           <desc>specify machine name</desc>
>     </service1>
>     <service1>
>           <label>second parameter</label>
>           <desc>specify machine IP</desc>
>     </service1>
>     <cmd> -p args1 -t args2 </cmd>
> </parameters>
> 
> XSL variable should give me value 2 as there are 2 'service1' 
> templates.
> 
> Case 2
> 
> <?xml version='1.0'?>
> <?xml-stylesheet href="service1.xsl" type="text/xsl"?>
> 
> <parameters>
>     <service2>
>           <label>first parameter</label>
>           <desc>specify machine name</desc>
>     </service2>
>     <service2>
>           <label>second parameter</label>
>           <desc>specify machine IP</desc>
>     </service2>
>     <service2>
>           <label>third parameter</label>
>           <desc>specify third param. as Y or N</desc>
>     </service2>
>     <service2>
>           <label>forth parameter</label>
>           <desc>specify forth param between 1 to 100</desc>
>     </service2>
>      <cmd> --name args1 --value args2 --decision args3 
> --percentage args4</cmd> </parameters>
> 
> XSL variable should give me value 4 as there are 4 'service2' 
> templates.
> 
> I am using perl:libxslt processor and using XSL version 1.0.I 
> want xsl command for giving desired outputs in both cases 
> above, So,how can I count total number of "service<no.>" 
> templates above using XSL variable(or any other xsl feature)?
> So that I will get total number of arguments for each service.
> ---------------------------------
> Thanks and Regards,
> Himanshu Padmanabhi

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-2007 All Rights Reserved.