Toon posts:

[XSL] String replace

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik zag al een aantal topics over dit onderwerp maar deze gingen of over translate() of over een ingewikkelde constructie.

<xsl:value-of select='functie'/>

Deze waarde roep ik nu uit, maar hierin staan spaties die vervangen moeten worden door een -

Is hier een simpele functie voor ?

  • TeeDee
  • Registratie: Februari 2001
  • Laatst online: 14-02 14:23

TeeDee

CQB 241

Hier vind ik toch wel aardig wat bruikbare tips tussen staan.

Heart..pumps blood.Has nothing to do with emotion! Bored


  • Cyphax
  • Registratie: November 2000
  • Laatst online: 21:09

Cyphax

Moderator LNX
Nee, wel in XSLT2, daar is de replace()-functie dan weer wel beschikbaar.
Hier staan nog wat tips over dit onderwerp:
http://www.dpawson.co.uk/xsl/sect2/replace.html

[ Voor 19% gewijzigd door Cyphax op 23-08-2006 15:03 ]

Saved by the buoyancy of citrus


  • Reinier
  • Registratie: Februari 2000
  • Laatst online: 00:41

Reinier

\o/

Je moet denk ik aan de slag met
substring-before
en
substring-after
.

[ Voor 5% gewijzigd door Reinier op 23-08-2006 15:10 ]


  • _Thanatos_
  • Registratie: Januari 2001
  • Laatst online: 23-12-2025

_Thanatos_

Ja, en kaal

Je kan ook een external function gebruiken. Maar dan moet je object model dat wel ondersteunen.

日本!🎌


Verwijderd

In XSLT 1 heb je de simpele functie "translate":
translate(value, from, to) ==> string.

in jouw situatie:
translate(functie, " ", "-") should do the trick.

  • Reinier
  • Registratie: Februari 2000
  • Laatst online: 00:41

Reinier

\o/

Ik dacht ook aan translate() , maar hij ik maakte uit de eerste zin van de TS op dat dat geen optie was.

Verwijderd

Topicstarter
XML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!-- pretend this is in a template -->
  <xsl:variable name="myString" select="'This%20is%20Test'"/>
  <xsl:variable name="myNewString">
    <xsl:call-template name="replaceCharsInString">
      <xsl:with-param name="stringIn" select="string($myString)"/>
      <xsl:with-param name="charsIn" select="'%20'"/>
      <xsl:with-param name="charsOut" select="' '"/>
    </xsl:call-template>
  </xsl:variable>
  <!-- $myNewString is a result tree fragment, which should be OK. -->
  <!-- If you really need a string object, do this: -->
  <xsl:variable name="myNewRealString" select="string($myNewString)"/>

<!-- here is the template that does the replacement -->
<xsl:template name="replaceCharsInString">
  <xsl:param name="stringIn"/>
  <xsl:param name="charsIn"/>
  <xsl:param name="charsOut"/>
  <xsl:choose>
    <xsl:when test="contains($stringIn,$charsIn)">
      <xsl:value-of select="concat(substring-before($stringIn,$charsIn),$charsOut)"/>
      <xsl:call-template name="replaceCharsInString">
        <xsl:with-param name="stringIn" select="substring-after($stringIn,$charsIn)"/>
        <xsl:with-param name="charsIn" select="$charsIn"/>
        <xsl:with-param name="charsOut" select="$charsOut"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$stringIn"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


Dit werkt uitstekend, thnx voor de tip
Pagina: 1