Jump to content

Counting data rows for a node.


Recommended Posts

Hi

 

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

 

<Contract>
<Lease>12345</Lease>
<trdate>12-sep-1990</trdate>
<customer id="1">
<name>tanket</name>
<country>timbaktu</country>
<creditrating>500</creditrating>
</customer>
<Locations>
<Location cillicode="13456">
<title>SharptonWorks</title>
<GPSCoordinate>17:45,36</GPSCoordinate>
</Location>
<Location cillicode="873456">
<title>MickeyTowers</title>
<GPSCoordinate>67:45,36</GPSCoordinate>
</Location>
</Locations>
<Phonegrp>
<HQ>
<vicepresident>1234567890</vicepresident>
<security>76543421</security>
<reception>123458899</reception>
</HQ>
<shipping>
<oilsandpaints>9876543210</oilsandpaints>
<steel>887772929</steel>
</shipping>
</Phonegrp>
</Contract>
--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>
</Locations>
<Phonegrp Count="2">
<HQ vicepresident="1234567890" security="76543421" reception="123458899"></HQ>
<shipping oilsandpaints="9876543210" steel="887772929"></shipping>
</Phonegrp>
</Contract>
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:copy>
<xsl:for-each select="@*|*[not(* or @*)]">
<xsl:attribute name="{name(.)}"><xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="*[* or @*]|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

 

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.

Guest
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.

Loading...
×
×
  • Create New...