[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Modify acronym replace "function"


Subject: Re: [xsl] Modify acronym replace "function"
From: Sven Waibel <sven.waibel@xxxxxxxx>
Date: Thu, 24 Nov 2005 09:28:51 +0100

I realised that it might be middle of the night :o)

I read your post at biglist but i can't get my code working.

Do you see what i'm doing wrong?

That's my code:


...
<xsl:template name="replace-acronyms">
  <xsl:param name="acronyms"
select="document('')/xsl:stylesheet/xsl:template[@name='acro']/acronyms" />
  <xsl:param name="string" />
  -- <xsl:copy-of select="$acronyms"/> -- <!-- Test -->
  <xsl:choose>
    <xsl:when test="not($acronyms)">
      <xsl:value-of select="$string" />
    </xsl:when>
    <xsl:when test="not(string($string))" />
    <xsl:otherwise>
      <xsl:variable name="acronym" select="$acronyms[1]/@acronym" />
      <xsl:choose>
        <xsl:when test="contains($string, $acronym)">
          <xsl:variable name="before" select="substring-before($string,
$acronym)" />
          <xsl:variable name="after" select="substring-after($string,
$acronym)" />
          <xsl:call-template name="replace-acronyms">
            <xsl:with-param name="string" select="$before" />
            <xsl:with-param name="acronyms" select="$acronyms[position()
>  1]" />
          </xsl:call-template>
          <acronym title="{$acronyms[1]}">
            <xsl:value-of select="$acronym" />
          </acronym>
          <xsl:call-template name="replace-acronyms">
            <xsl:with-param name="string" select="$after" />
            <xsl:with-param name="acronyms" select="$acronyms" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="replace-acronyms">
            <xsl:with-param name="string" select="$string" />
            <xsl:with-param name="acronyms" select="$acronyms[position()
>  1]" />
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="acro">
<acronyms>
	<acronym acronym="vorbedingung">PRECONDITION</acronym>
	<acronym acronym="Vorbedingung">PRECONDITION</acronym>
	<acronym acronym="VORBEDINGUNG">PRECONDITION</acronym>
	<acronym acronym="nachbedingung">POSTCONDITION</acronym>
	<acronym acronym="Nachbedingung">POSTCONDITION</acronym>
	<acronym acronym="NACHBEDINGUNG">POSTCONDITION</acronym>
	<acronym acronym="beschreibung">DESCRIPTION</acronym>
	<acronym acronym="Beschreibung">DESCRIPTION</acronym>
	<acronym acronym="BESCHREIBUNG">DESCRIPTION</acronym>
</acronyms>
</xsl:template>
...

Ragulf Pickaxe schrieb:
> Good morning to you, as well Sven (you do realise that it might be
> evening or in the middle of the night elsewhere :-)
> 
> If you want to hold the variable in the xsl document, then you will
> have to do something like this:
> 
> At the top level:
> 
>><acronyms>
>>       <acronym acronym="vorbedingung">PRECONDITION</acronym>
>>       <acronym acronym="Vorbedingung">PRECONDITION</acronym>
>>       <acronym acronym="VORBEDINGUNG">PRECONDITION</acronym>
>></acronyms>
> 
> 
> Then have a variable (also top-level) like this:
> <xsl:variable name="acronyms" select="document('')/xsl:stylesheet/acronyms"/>
> 
> This will select the acronyms element, and you will be able to
> navigate through its children.
> 
> You can also take a look at the thread starting at this point:
> http://www.biglist.com/lists/xsl-list/archives/200210/msg01196.html
> 
> Regards,
> Ragulf Pickaxe :-)


Current Thread
Keywords
xsl