This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Continuing problem
- To: John Ericson <john at john dot pp dot se>
- Subject: Re: [xsl] Continuing problem
- From: Jeni Tennison <jeni at jenitennison dot com>
- Date: Thu, 1 Nov 2001 16:20:58 +0000
- CC: XSL-List at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <20011101001307.C2502@highs-compis.spaze><292847905.20011101095943@jenitennison.com><20011101162624.A1301@highs-compis.spaze>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi John,
> Anyway I rearranged my template to look like the above and it works
> fine. But In my larger work I need to have an template that matches
> "link".
Ah. OK, then you need the info template to just apply templates to
all its children as before, and you need to do some clever business
within the text() template to work out what to do. I think that the
rules are that it should emit the normalized string, plus:
* a space before the normalized string if there is a normalized
string and the original string had whitespace as its first
character
* a space after the normalized string if there is a normalized
string and the original string had whitespace as its last
character
This gives you a template like:
<xsl:template match="text()">
<xsl:variable name="normalizedString" select="normalize-space()" />
<xsl:if test="not(normalize-space(substring(., 1, 1)))">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="$normalizedString" />
<xsl:if test="not(normalize-space(substring(., string-length())))">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
By the way:
> <xsl:template match="link">
> <xsl:apply-templates/>
> <xsl:text>[</xsl:text>
> <xsl:value-of select="count(preceding::link)+1"/>
> <xsl:text>]</xsl:text>
> </xsl:template>
Could be more neatly written as:
<xsl:template match="link">
<xsl:apply-templates />
<xsl:number level="any" format="[1]" />
</xsl:template>
(assuming that link elements don't nest inside each other, or if they
do you want them sequentially numbered)
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list