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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...