Subject: Re: [xsl] Grouping data at multiple levels (can XSL do this?) From: Michael Kay <mike@xxxxxxxxxxxx> Date: Tue, 28 Jun 2011 22:17:16 +0100 |
Michael Kay Saxonica
Hello,
I'm writing to this list for the first time because after using XSL for some years I've come across a data pattern that I think defies use by XSL. It is the kind of thing that a language that allows you to alter/update variables and iterate through lists can do with relative ease, but I don't find it possible with XSL. It is an example of hierarchical meaning within flat data, that is, there are groups of rows of data, but some groups represent updates to information in prior groups.
In pseudo code, something like this
for each<receiver> if (the<receiver> has a child<model-code>) then create the element<myReceiverHistory> with all the children of <receiver> for each following-sibling of receiver that does not have a <model-code> child create a new<myReceiverHistory> by updating the most recent with children info.
It is the kind of thing that loop construct with variables that can be updated within the loop or that has a "continue" to skip to the next, etc. can do.
Happy to be proved wrong or listen to your interest.
I can pull rows out of a database and put them into an xml format. They are tidbits that, when sorted by date, create a group of changes that occur on permanent GPS site. So, starting from this:
<result xmlns="">
<row>
<site-transaction-type>frequency standard</site-transaction-type>
<site-transaction-name>type</site-transaction-name>
<site-transaction-value>INTERNAL</site-transaction-value>
<effective-date>1990-01-09T00:00:00.000</effective-date>
</row>
<row>
<site-transaction-type>frequency standard</site-transaction-type>
<site-transaction-name>additional information</site-transaction-name>
<site-transaction-value>ROGUE SNR-8 uses external rubidium standard</site-transaction-value>
<effective-date>1990-01-09T00:00:00.000</effective-date> </row>
<row>
...etc. etc.
I can use for-each-group to
<xsl:variable name="receivers">
<xsl:for-each-group select="$transactions/row[site-transaction-type='receiver']" group-by="effective-date">
<sopac:receiver xmlns:sopac="http://sopac.ucsd.edu/ns">
<xsl:copy-of select="current-group()"/>
</sopac:receiver>
</xsl:for-each-group>
</xsl:variable>
Which allows me to put all the things together that make up the actual transaction. The catch is that only when one of the rows is a "site-transaction-name" with the value 'model code' does it represent a change to the receiver. Other changes, e.g. 'serial number' only update the previous group of elements. The above creates this:
<sopac:receiver xmlns:sopac="http://sopac.ucsd.edu/ns"> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>model code</site-transaction-name> <site-transaction-value>TRIMBLE 4000SST</site-transaction-value> <effective-date>1990-02-09T00:00:00.000</effective-date> </row> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>firmware version</site-transaction-name> <site-transaction-value>4.11</site-transaction-value> <effective-date>1990-02-09T00:00:00.000</effective-date> </row> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>serial number</site-transaction-name> <site-transaction-value>496</site-transaction-value> <effective-date>1990-02-09T00:00:00.000</effective-date> </row> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>satellite system</site-transaction-name> <site-transaction-value>GPS</site-transaction-value> <effective-date>1990-02-09T00:00:00.000</effective-date> </row> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>additional information</site-transaction-name> <site-transaction-value>First measurements</site-transaction-value> <effective-date>1990-02-09T00:00:00.000</effective-date> </row> </sopac:receiver> <sopac:receiver xmlns:sopac="http://sopac.ucsd.edu/ns"> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>serial number</site-transaction-name> <site-transaction-value>422</site-transaction-value> <effective-date>1990-02-14T00:00:00.000</effective-date> </row> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>sample interval</site-transaction-name> <site-transaction-value>30</site-transaction-value> <effective-date>1990-02-14T00:00:00.000</effective-date> </row> <row xmlns=""> <site-transaction-type>receiver</site-transaction-type> <site-transaction-name>additional information</site-transaction-name> <site-transaction-value>Site ties 05-MAR-1990</site-transaction-value> <effective-date>1990-02-14T00:00:00.000</effective-date> </row> </sopac:receiver>
...
Even creating a variable with the necessary hierarchy is problematic because I can't go back to get the data -- or maybe I can with a tricky previous-sibling ?
Thanks, Hank
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping data at multiple, Peter Flynn | Thread | Re: [xsl] Grouping data at multiple, Wendell Piez |
Re: [xsl] Grouping data at multiple, Peter Flynn | Date | Re: [xsl] Grouping data at multiple, Wendell Piez |
Month |