Re: [xsl] RE: A simple solution (Was: Re: One for tomorrow :-) )

Subject: Re: [xsl] RE: A simple solution (Was: Re: One for tomorrow :-) )
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 4 Jul 2001 16:13:42 +0100
Hi Daniel,

>From your earlier descriptions, you want to merge all the NameAddressN
elements up to and including the one that ends in a comma, to give the
name, and then merge all the NameAddressN after the one that ends in a
comma to give the address.

In a template matching the GetTableData element, you can find the
NameAddressN element that ends with a comma with:

  <xsl:variable name="last-name-element"
    select="cs:*[starts-with(local-name(), 'NameAddress') and
                 substring(., string-length(.)) = ',']" />

To get the name, you can find all the NameAddressN elements that come
before this element, and iterate over them with:

     select="cs:*[starts-with(local-name(), 'NameAddress') and
                  following-sibling::cs:*[generate-id() =
    <xsl:value-of select="." />

And then get the value of the line ending with the comma, but without
the comma, with:

     select="substring($last-name-element, 1,
                       string-length($last-name-element) - 1)" />

To get the address, you can iterate over all the NameAddressN elements
that come *after* the element that ends in a comma with:

     select="cs:*[starts-with(local-name(), 'NameAddress') and
                  preceding-sibling::cs:*[generate-id() =
    <xsl:value-of select="." />

Alternatively, if you don't care about preserving the lines of the
address and can guarantee that the elements won't hold a comma before
the one that separates the name from the address, then you could
generate a string by concatenating all the NameAddressN elements:

  <xsl:variable name="NameAddress">
         select="cs:*[starts-with(local-name(), 'NameAddress')]">
       <xsl:value-of select="." />

And then split this string using substring-before() and
substring-after() to get the name and address.  You can get the name

  <xsl:value-of select="substring-before($NameAddress, ',')" />

And get the address with:

  <xsl:value-of select="substring-after($NameAddress, ',')" />



Jeni Tennison

 XSL-List info and archive:

Current Thread