Frage

Is there an easy way of normalizing the slashes of a URL with XSLT?

In my example I'm converting RSS feeds with XSLT and I want to build the URLs for the tags. I can do this with the following line:

<skos:Concept about="{/rss/channel/link}/tag/{@nicename}">

or

<skos:Concept about="{/rss/channel/link}tag/{@nicename}">

Sometimes the link has a trailing slash and sometimes not. Is there an easy function, which will make sure that there is always a slash? e.g.:

<skos:Concept about="{normalize-slashs(/rss/channel/link/)}tag/{@nicename}">
War es hilfreich?

Lösung

Assuming your link contains no spaces, try =

translate(normalize-space(translate(/rss/channel/link, '/', ' ')), ' ', '/')

Edit:

To remove the closing slash from $string, if it exists:

substring($string, 1, string-length($string) - (substring($string, string-length($string))='/'))

In XSLT 2.0 this can be shortened by using the ends-with() function.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top