Re: [xsl] unique-sequence-numbering

Subject: Re: [xsl] unique-sequence-numbering
From: "Yates, Danny (ANTS)" <danny.yates@xxxxxxxxxx>
Date: Thu, 8 Aug 2002 14:12:03 +0100
Hi,

Sorry if this message doesn't thread properly - I'm normally a
digest subscriber, so I'm having to "fake it"! Also, sorry if
it's a duplicate - I'm not sure my earlier copy got out. So,
not a great start then...

>  <?xml version="1.0"?>
>  <students>
>      <student id = "101">
>        <name>A</name>
>        <address>XXX</address>
>      </student>
>      <student id = "201">
>        <name>B</name>
>        <address>YYY</address>
>      </student>
>      <student id = "301">
>        <name>C</name>
>        <address>XXX</address>
>      </student>
>      <student id = "401">
>        <name>E</name>
>      <address>YYY<address>
>    </student>
>  </students>

Here is some XSL-like pseudo-code which may help. My XSL is not
hot enough to make it up on-the-fly and I don't want to confuse
you by sending something which looks a lot like XSL, but isn't!

template match="students"
  call-template name="OutputStudent"
    with-param node=student[1]
    with-param seq=1

template name="OutputStudent"
  param node
  param seq

  if $node/address = "YYY"
    write out CSV line including $seq
    write out CSV line including ($seq + 1)
    call-template name="OutputStudent"
      with-param node=$node/following-sibling::student[1]
      with-param seq=$seq + 2

  if not($node/address = "YYY")
    write out CSV line including $seq
    call-template name="OutputStudent"
      with-param node=$node/following-sibling::student[1]
      with-param seq=$seq + 1

An alternative implementation of the OutputStudent template:

template name="OutputStudent"
  param node
  param seq
  param already-repeated default 0

  write out CSV line including $seq

  if ($node/address = "YYY") and ($already-repeated = 0)
    call-template name="OutputStudent"
      with-param node=.
      with-param seq=$seq + 1
      with-param already-repeated=1

  if not(($node/address = "YYY") and ($already-repeated = 0))
    call-template name="OutputStudent"
      with-param node=$node/following-sibling::student[1]
      with-param seq=$seq + 1

This separates out the CSV writing code, but makes the 'if'
statements a bit more complex.

You may have to think a bit about the "base case" which stops
recurrsion, i.e. if there is no following-sibling.

Hope that helps,

Dan.

-- 
Danny Yates
Technical Architect
Abbey National Treasury Services
E-mail: Danny.Yates@xxxxxxxxxx


***************************************************************************
This communication (including any attachments) contains confidential information.  If you are not the intended recipient and you have received this communication in error, you should destroy it without copying, disclosing or otherwise using its contents.  Please notify the sender immediately of the error.

Internet communications are not necessarily secure and may be intercepted or changed after they are sent.  Abbey National Treasury Services plc does not accept liability for any loss you may suffer as a result of interception or any liability for such changes.  If you wish to confirm the origin or content of this communication, please contact the sender by using an alternative means of communication.

This communication does not create or modify any contract and, unless otherwise stated, is not intended to be contractually binding.

Abbey National Treasury Services plc. Registered Office:  Abbey National House, 2 Triton Square, Regents Place, London NW1 3AN.  Registered in England under Company Registration Number: 2338548.  Regulated by the Financial Services Authority (FSA).
***************************************************************************


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread