Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Re: count(preceding-sibling ) not working

From: "Michael Kay" <mike@------------>
To:
Date: 12/3/2007 1:27:00 PM
> What I want to do is to count the total number of Accrual 
> nodes that precede the current Accrual node. Both the 
> siblings of the current Accrual node and any Accrual children 
> of all preceding Accruals nodes.

Sounds like

count(preceding::Accrual)

or <xsl:number level="any"/>

but be aware that either of these could be expensive

Michael Kay
http://www.saxonica.com/

> 
> 
> I have tried this:
> 
> <xsl:for-each 
> select="expensys:Lines/expensys:Line/expensys:Accruals/expensy
> s:Accrual">
> 
> <txn:PSIBS>
>    <xsl:number value="count(preceding-sibling::*)"/>
> </txn:PSIBS>
> 
> 
> I cannot use a filter on the for-each loop 'cos AFAICS this 
> would mean restructuring the whole transform. With my current 
> level of XSL knowledge that would take an unacceptably long time :-)
> 
> 
> Many thanks for any help....
> 
> 
> Adam
> 
> 
> 
> Sample input file snippet:
> 
> 
>      <Lines>
>        <Line>
>          <ItemDescription><![CDATA[MAPIC - Trip to see venues 
> for drinks reception]]></ItemDescription>
>          <ItemNumber><![CDATA[1]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-01T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[6350]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[72000]]></accountCode>
>              <amount>
>                <value><![CDATA[15.50]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[MAPIC - Taxi airport to 
> home ]]></ItemDescription>
>          <ItemNumber><![CDATA[2]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-01T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[6350]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[72000]]></accountCode>
>              <amount>
>                <value><![CDATA[53.90]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[MAPIC - Viewing venues for 
> drinks reception]]></ItemDescription>
>          <ItemNumber><![CDATA[3]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-02T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[6350]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[72010]]></accountCode>
>              <amount>
>                <value><![CDATA[193.85]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[4]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-13T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[12.00]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[5]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-13T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[12.00]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[6]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-13T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[49.32]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[7]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-14T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[5.70]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[8]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-14T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[15.00]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[9]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-23T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[4.99]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[FPGC - Photo and frame for 
> PMT as requested by James 
> Darkins]]></ItemDescription>
>          <ItemNumber><![CDATA[10]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-23T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[73430]]></accountCode>
>              <amount>
>                <value><![CDATA[17.43]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>            <Accrual>
>              <accountCode><![CDATA[30540]]></accountCode>
>              <amount>
>                <value><![CDATA[3.05]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[11]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-24T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[13.91]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>        <Line>
>          <ItemDescription><![CDATA[Personal spend]]></ItemDescription>
>          <ItemNumber><![CDATA[12]]></ItemNumber>
>          <SpendDate><![CDATA[2007-10-28T00:00:00+01:00]]></SpendDate>
>          <CostCentre>
>            <costCentreCode><![CDATA[FPGC]]></costCentreCode>
>            <externalReference1><![CDATA[2003]]></externalReference1>
>          </CostCentre>
>          <ProjectCode><![CDATA[9000]]></ProjectCode>
>          <Accruals>
>            <Accrual>
>              <accountCode><![CDATA[999998]]></accountCode>
>              <amount>
>                <value><![CDATA[2.37]]></value>
>                <sense><![CDATA[debit]]></sense>
>              </amount>
>            </Accrual>
>          </Accruals>
>        </Line>
>      </Lines>
> 
> 
> 
> 
> 
> David Carlisle wrote:
> >> What am I doing wrong?
> > 
> > well you haven't shown any sopurce code, so we have to guess, but
> > presumably you get 0 bcause there are no preceding siblings.
> > that is children of the same parent.  If each Accruals 
> element just has
> > a single Accrual child, then that will be the case.
> > 
> > 
> >> I know could use "position()", but after I solve this 
> problem I need to apply a filter to the PSIBS 
> >> value.
> > 
> > 
> > Most likely you just need to do the filter before you use position.
> > 
> > 
> > <xsl:for-each
> > 
> select="expensys:Lines/expensys:Line/expensys:Accruals/expensy
> s:Accrual[some
> > filter goes here">
> > 
> > <txn:PSIBS>
> > <xsl:value-of select="position()"/>
> > </txn:PSIBS>
> > 
> > 
> > David
> > 
> > 
> > 
> > 
> ______________________________________________________________
> __________
> > The Numerical Algorithms Group Ltd is a company registered 
> in England
> > and Wales with company number 1249803. The registered office is:
> > Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
> > 
> > This e-mail has been scanned for all viruses by Star. The service is
> > powered by MessageLabs. 
> > 
> ______________________________________________________________
> __________
> > 
> > 
> > 
> > 
> 
> -- 
> Adam Lipscombe
> 
> T: 01872 575083
> M: 07957 548686
> E: adam.lipscombe@xxxxxxxxxx


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent