473,787 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL XML Number count issue

1 New Member
First post so please excuse any Faux Pas's

I have an xml file as below

<?xml version="1.0"?>
<Car>
<Type>Ford Sierra</Type>
<Service>1
<Date>01/09/2006</Date>
<Tyres>OK</Tyres>
<Oil>Filled</Oil>
<Water>Filled </Water>
</Service>
<Service>2
<Date>01/09/2005</Date>
<Tyres>OK</Tyres>
<Oil>Filled</Oil>
<Water>Filled </Water>
</Service>
<Service>3
<Date>01/09/2004</Date>
<Tyres>OK</Tyres>
<Oil>Filled</Oil>
<Water>Filled </Water>
</Service>
</Car>

I want to produce the below xml file from this

<?xml version="1.0"?>
<CarHistory>
<Type>Ford Sierra</Type>
<NoOfServices>3 </NoOfServices>Fo rd Sierra
<ServiceDetails >
<ServiceNo>1</ServiceNo> <!-- note the count -->
<Date>01/09/2006</Date>
<Water>Filled </Water>
</ServiceDetails>
<ServiceDetails >
<ServiceNo>2</ServiceNo> <!-- note the count increase by 1 -->
<Date>01/09/2005</Date>
<Water>Filled </Water>
</ServiceDetails>
<ServiceDetails >
<ServiceNo>3</ServiceNo> <!-- note the count increase by 1 again and should do till end of services -->
<Date>01/09/2004</Date>
<Water>Filled </Water>
</ServiceDetails>
</CarHistory>

So far my xls looks like this

<?xml version='1.0' ?>
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<CarHistory>
<Type>
<xsl:choose>< !-- Test to see if Type is there or if it has no value -->
<xsl:when test="Car/Type and '' != Car/Type"><!--If it is return the Value -->
<xsl:value-of select="Car/Type"/>
</xsl:when><!-- If its not return "Not Given" -->
<xsl:otherwise> Not Given</xsl:otherwise>
</xsl:choose>
</Type>
<NoOfServices >
<xsl:value-of select="count(C ar/Service)"/>
</NoOfServices>
<xsl:apply-templates/>
</CarHistory>
</xsl:template>
<xsl:template match="Service" >
<ServiceDetails >
<ServiceNo>
<!-- here lies the problem -->
</ServiceNo>
<Date>
<xsl:value-of select="Date"/>
</Date>
<Water>
<xsl:value-of select="Water"/>
</Water>
</ServiceDetails>
</xsl:template>
</xsl:stylesheet>

I wish to find the simplest way to have the <ServiceNo> increment by 1 each time around Position() does not seem to help me here as it increases by 2.

<xsl:number count="ServiceN o"/> fails as well as it has to go through a .net parser.

Thanks in advance.

Stan
Oct 15 '07 #1
1 1733
jkmyoung
2,057 Recognized Expert Top Contributor
As stated in SSDN

<xsl:value-of select="1 + count(preceding ::ServiceNo)"/>

Don't know why .Net doesn't support <xsl:number> as it is an xslt 1.0 feature.
What version are you using?

According to this: http://www.topxml.com/xslt/ the number solution should be supported in MSXML 3 and up.
Oct 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2640
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For example, my customer table has 1 million unique records, so the results of the following query are as such: select count(customer_nbr) from customer = 1,000,000 There is bit field in the customer table that denotes whether a
6
4152
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the end is found is less efficient than using sizeof operator , since size of the array is completely determined at compile time. i don't quite understand this. Could anyone explain to me in detail ?
8
18554
by: trint | last post by:
I have a select statement that all I want to do is get the number of rows returned in my query: string strSQLAccountInfo1 = "select * " + "FROM orders " + "where user_id = '" + Class1.loginUserid.Trim() + "' "; SqlCommand cmdAL = new SqlCommand(strSQLAccountInfo1, cnSQLAccountInfo1);
7
19864
sharijl
by: sharijl | last post by:
I have a SQL query which returns the total amount of issues: SELECT issue,Count(issue) as total FROM mytable Group by issue This works but I need the total of the same catagory in three tables so I assumed a union would work so tried something like this: SELECT issue,Count(issue) as total FROM mytable Group by issue Union SELECT issue,Count(issue) as totalFROM mytable2 Group by issue union
2
3097
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I have a gridview with paging enabled. I need to know how many rows of data are on the last page!!! When I look at the Gridview1.Rows.Count in the Page_Load, it always returns the number that the paging is set to... currently 13, but if there are only 4 rows on the last page, I need to know that there are only 4 rows.
1
3619
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent via an email function. But just can't figure it out. <? //////////////////////////////////////////////////////////// //
58
4934
by: sh.vipin | last post by:
is there any way to find out number of bytes freed on a particular free() call in C
1
7781
by: santoshsri | last post by:
Hi All, My C# web application calls a webservice to process a report. It sends XMLs as parameter and in response gets an XML node which stores Binay datatype bin.base64. It makes an instance of the proxy class of webservice and makes a synchronous call to webservice GetReport() op. Here is the code snippet - *************************************************************************************** wbFELIP.wsZProcessReport.ProcessReport...
2
5569
by: ems9tech | last post by:
I can't get this count to return a number without an empty quote at the end ( " ) or getting NaN. Does anyone know why? I've searched and don't see any other postings on this issue. I'm using VS 2008. Thanks for any and all pointers!!! XML file: <?xml version="1.0" encoding="utf-8"?> <CFF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" FormCount="1" TotalFormCount="501"...
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.