Subject: RE: [xsl] Mandatory and Missing Columns From: Shashank Jain <shashankjain@xxxxxxxx> Date: Tue, 6 Apr 2010 18:03:29 -0500 |
Thank you very much for this. I forgot to mention that I am using xslt 2.0 and used the tokenize function to calculate variable. Thanks again. Shashank > Date: Tue, 6 Apr 2010 09:37:14 +0200 > From: wolfgang.laun@xxxxxxxxx > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] Mandatory and Missing Columns > > The main difficulty here is that you haven't provided a definition of > the composition of the list of mandatory document types in > @sp_mand_doctypes. Are the separators ", " or just "," or both? The > separators must be included in the contains test since at least one > document type is a substring of another one. > > So, assuming just ", " as delimiter: > > <xsl:param name="sep" select="', '"/> > > <xsl:template match="/"> > > <xsl:for-each select="//document_type[generate-id() = > generate-id(key('docType',@sp_document_type)[1])]"> > <xsl:variable name="doctype" select="@sp_document_type"/> > <tr> > <xsl:variable name="events" > > select="/data/event_template[contains(concat($sep,@sp_mand_doctypes,$sep),con cat($sep,$doctype,$sep))]/event"/> > <xsl:variable name="required" select="count($events)"/> > <xsl:variable name="evreps" > select="count($events/document_type[@sp_document_type = $doctype])"/> > > <td><xsl:value-of select="@sp_document_type"/></td> > <td><xsl:value-of select="$required"/></td> > <td><xsl:value-of select="$required - $evreps"/></td> > </tr> > </xsl:for-each> > </xsl:template> > > If "," does occur or just to be on the safe side, another contains() > test has to be added, enclosing $doctype in a pair of strings: > concat(",", $doctype, ",") > > If you have XSLT 2.0, you can simply use: > > <xsl:variable name="events" > select="/data/event_template[tokenize(@sp_mand_doctypes,'\s*,\s*') > = $doctype]/event"/> > > -W > > On Mon, Apr 5, 2010 at 11:58 PM, Shashank Jain <shashankjain@xxxxxxxx> wrote: >> >> Hello All, >> >> I am trying to create a table which has 3 columns like >> >> Stock Report 6 3 >> >> >> >> Report 0 0 >> >> >> >> EPS Model 7 5 >> >> >> >> Articles 0 0 >> >> DCF Model 4 3 >> >> first column list all the sp_document_types. Second Column list the total # of events in which the document type is mandatory and the third column list total number of events in which sp_document_type is missing. >> >> Here is my XML >> >> <data business_group_id="is_er"> >> <event_template sp_mand_doctypes="Research Note, Prior Stock Report - Edited / Reviewed, Stock Report"> >> <event complete="N" /> >> <event complete="N"> >> <document_type complete="Y" sp_document_type="Stock Report"/> >> <document_type complete="Y" sp_document_type="Report"/> >> </event> >> <event complete="N"> >> <document_type complete="Y" >> sp_document_type="Stock Report"/> >> </event> >> </event_template> >> >> <event_template sp_mand_doctypes="EPS Model,Stock Report"> >> <event >> complete="N" /> >> <event complete="N"> >> <document_type complete="Y" sp_document_type="EPS Model"/> >> >> </event> >> >> <event complete="N"> >> >> <document_type complete="Y" >> sp_document_type="Stock Report"/> >> >> </event> >> >> </event_template> >> >> <event_template sp_mand_doctypes="DCF Model, EPS Model"> >> >> <event >> complete="N" /> >> >> <event complete="N"> >> >> >> <document_type complete="Y" sp_document_type="Articles"/> >> >> >> <document_type complete="Y" sp_document_type="EPS Model"/> >> >> >> </event> >> >> >> <event complete="N"> >> >> >> <document_type complete="Y" >> sp_document_type="Stock Report"/> >> >> >> </event> >> <event complete="N"> >> >> >> >> <document_type complete="Y" sp_document_type="Articles"/> >> >> >> >> <document_type complete="Y" sp_document_type="DCF Model"/> >> >> >> >> </event> >> >> >> </event_template> >> </data> >> >> First column list all the sp_document_types >> Stock Report >> Report >> EPS Model >> Articles >> DCF Model >> >> For this I created one key function >> <xsl:key name="docType" match="document_type" use="@sp_document_type"/> >> >> and used it like this >> >> <xsl:for-each select="//document_type[generate-id() = generate-id(key('docType',@sp_document_type)[1])]"> >> <tr> >> <td> >> <xsl:value-of select="@sp_document_type"/> >> </td> >> <tr> >> </xsl:for-each> >> >> I was able to achieve the first column. >> >> In the second column I want in how many events sp_document_type is required. >> It means if we look at the first 'event_template' it has 3 mandatory documents (Research Note, Prior Stock Report - Edited / Reviewed, Stock Report) which should be present in the every 'event' child of event_template. But "Stock report" is present in only 2 'events' of that 'event_template'. >> Similarly second event_template has 2mandatory documents "EPS Model" and "Stock report" and both the documents are present in one event but they were required in all the events. >> So my table will look some thing like >> >> Stock Report 3+3+0 (since Stock report is not required in 3rd event_template) >> >> Report 0+0+0 (It is not required in any of the event_template) >> >> EPS Model 0+3+4 >> >> Articles 0+0+0 >> DCF Model 0+0+4 >> >> In the thrid column I am trying to list total number of events in which 'sp_document_type' is missing. >> It means, if we again look at the first event_template 'Stock Report' is one of the mandatory document but it is missing in one of the event of event_template. Similarly Stock Report is missing from the 2 of the events of the second event_template. >> Stock Report 1+2+0 >> >> >> Report 0+0+0 >> >> >> EPS Model 0+2+3 >> >> >> Articles 0+0+0 >> DCF Model 0+0+3 >> >> I will appreciate if somebody can advice me in figuring out other two columns. >> >> Thanks >> Shashank Jain >> >> >> >> _________________________________________________________________ >> The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. >> http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=PID283 26::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_5 > _________________________________________________________________ The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID2832 6::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Mandatory and Missing Col, Wolfgang Laun | Thread | RE: [xsl] Mandatory and Missing Col, Wendell Piez |
Re: [xsl] Mandatory and Missing Col, Wolfgang Laun | Date | Re: [xsl] Create Table, Eric J. Bowman |
Month |