L
lennyw
Hi
I'm trying to use XSLT to do an xml to xml transformation where the
output xml contains summary data on the information in the input xml.
I've succesfully done a Muenchian grouping of the data from the input
xml file, but I can't see how to operate on the grouped result to
create and output the desired summary data. If someone could give a
reference to an example or provide an actual example I'd really
apprecaite it.
The actual stylesheet for the gouper is shown below. It groups data for
each input "row" element by "optionSymbol". Once the data is fully
grouped, I have data in ascending order of "optionSymbol", with the
same optionSymbols together. Which is a good first step. And it works.
But now what I'd like to do is sum the values of certain fields across
"row" elements, average the values of certain fields across
"row"elements, etc. but do the operations only on row elements sharing
the same "optionSymbol" Once these summary values have been
calculated, I want to output ONE "row" element containg the summary
data and the optionSymbol text for each disticnt optionSymbol in the
grouped list. Sort of like what you'd see someone do in a simple
spreadsheet.
I simply don't see how to accomplish this.
The thing that has me most confused is if there exists an accessible
node list of the grouped data at the start of the inner for loop of the
Muenchian grouper. And if so, how I get at it. If not, is there an
accessible node list of the grouped nodes after the inner for loop
ends? And how to get at it ?
I apologize if this question seems naive, but I've only been doing XSL
for a few weeks, and I'm trying to use it to create real production
code. A tall order (for me at least), but that's what's needed!
I'm wondering if this is even possible with XSLT.
Here is the XSLT for my Muenchian grouper (adapted from the OReilly
book):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl
utput method="xml" indent="no"/>
<xsl:variable name="nl">
<xsl:text>
</xsl:text>
</xsl:variable>
<!-- Group option symbols -->
<xsl:key name="optionSymbol" match="tr" use="td[20]"/>
<xsl:template match="/">
<xsl:for-each
select="//tr[generate-id(.)=generate-id(key('optionSymbol',
td[20])[1])]">
<xsl:sort select="td[20]"/>
<!-- Now group each row which matches the current optionSymbol -->
<!-- This gives us a full group of rows for each option symbol -->
<xsl:for-each select="key('optionSymbol', td[20])">
<!--SUMMARY SELECTION/ CALCULATION SHOULD HAPPEN HERE-->
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Thanks in advance for any help.
Lenny Wintfeld
I'm trying to use XSLT to do an xml to xml transformation where the
output xml contains summary data on the information in the input xml.
I've succesfully done a Muenchian grouping of the data from the input
xml file, but I can't see how to operate on the grouped result to
create and output the desired summary data. If someone could give a
reference to an example or provide an actual example I'd really
apprecaite it.
The actual stylesheet for the gouper is shown below. It groups data for
each input "row" element by "optionSymbol". Once the data is fully
grouped, I have data in ascending order of "optionSymbol", with the
same optionSymbols together. Which is a good first step. And it works.
But now what I'd like to do is sum the values of certain fields across
"row" elements, average the values of certain fields across
"row"elements, etc. but do the operations only on row elements sharing
the same "optionSymbol" Once these summary values have been
calculated, I want to output ONE "row" element containg the summary
data and the optionSymbol text for each disticnt optionSymbol in the
grouped list. Sort of like what you'd see someone do in a simple
spreadsheet.
I simply don't see how to accomplish this.
The thing that has me most confused is if there exists an accessible
node list of the grouped data at the start of the inner for loop of the
Muenchian grouper. And if so, how I get at it. If not, is there an
accessible node list of the grouped nodes after the inner for loop
ends? And how to get at it ?
I apologize if this question seems naive, but I've only been doing XSL
for a few weeks, and I'm trying to use it to create real production
code. A tall order (for me at least), but that's what's needed!
I'm wondering if this is even possible with XSLT.
Here is the XSLT for my Muenchian grouper (adapted from the OReilly
book):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl
<xsl:variable name="nl">
<xsl:text>
</xsl:text>
</xsl:variable>
<!-- Group option symbols -->
<xsl:key name="optionSymbol" match="tr" use="td[20]"/>
<xsl:template match="/">
<xsl:for-each
select="//tr[generate-id(.)=generate-id(key('optionSymbol',
td[20])[1])]">
<xsl:sort select="td[20]"/>
<!-- Now group each row which matches the current optionSymbol -->
<!-- This gives us a full group of rows for each option symbol -->
<xsl:for-each select="key('optionSymbol', td[20])">
<!--SUMMARY SELECTION/ CALCULATION SHOULD HAPPEN HERE-->
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Thanks in advance for any help.
Lenny Wintfeld