473,386 Members | 1,720 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,386 software developers and data experts.

XSL XML Number count issue

1
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>Ford 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:stylesheet 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(Car/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="ServiceNo"/> fails as well as it has to go through a .net parser.

Thanks in advance.

Stan
Oct 15 '07 #1
1 1722
jkmyoung
2,057 Expert 2GB
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
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...
6
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...
8
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 = '" +...
7
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...
2
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...
1
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...
58
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
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.