This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Continuing problem


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]