[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: RE: A simple solution (Was: Re: One for tomorrow :

Subject: Re: RE: A simple solution (Was: Re: One for tomorrow :-) )
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 4 Jul 2001 16:13:42 +0100
Re:  RE: A simple solution (Was: Re: One for tomorrow :
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:

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

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

  <xsl:value-of
     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:

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

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">
     <xsl:for-each
         select="cs:*[starts-with(local-name(), 'NameAddress')]">
       <xsl:value-of select="." />
     </xsl:for-each>
  </xsl:variable>

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

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

And get the address with:

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

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.