Jump to content

Counting data rows for a node.


Recommended Posts



I have a problem with counting the number of data rows for an XML nodes. A sample XML is listed below.


<customer id="1">
<Location cillicode="13456">
<Location cillicode="873456">
--this would have to be transformed to
--within each data rows the elements become attributes for the data row.
--the number of data rows for a group is then counted.
<Contract Lease="12345" trdate="12-sep-1990">
<customer id="1" name="tanket" country="timbaktu" creditrating="500"></customer>
<Locations Count="2">
<Location cillicode="13456" title="SharptonWorks" GPSCoordinate="17:45,36"></Location>
<Location cillicode="873456" title="MickeyTowers" GPSCoordinate="67:45,36"></Location>
<Phonegrp Count="2">
<HQ vicepresident="1234567890" security="76543421" reception="123458899"></HQ>
<shipping oilsandpaints="9876543210" steel="887772929"></shipping>
The generic XSLT below translates the elements into named attributes but am running into issues trying to set the row count for the immediate parent node as described above
The node that would qualify to receive the count would be the one which nearest parent which has no Named attributes on it.
Is this something which can be easily addressed.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:for-each select="@*|*[not(* or @*)]">
<xsl:attribute name="{name(.)}"><xsl:value-of select="."/>
<xsl:apply-templates select="*[* or @*]|text()"/>


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...