Jump to content

Counting data rows for a node.


ckannan

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