|
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:
<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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] RE: A simple solution (Wa, Daniel Newman | Thread | RE: [xsl] RE: A simple solution (Wa, Tim Watts |
| RE: [xsl] Empty nodes - more inform, Dominic J. Blythe | Date | Re: [xsl] Removing XML:space from o, David Carlisle |
| Month |