Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris 110 posts 21 karma points
    Feb 03, 2009 @ 16:00
    Chris
    0

    Create automatic link with XSLT

    Hi,
    I would like to make a xslt function which looks in the bodytext of a node and when 1 of the words in the bodytext contains a word that is also in the 'Verklarende woordenlijst' (see image) as a node then the word in the bodytext gets linked to the node in the 'Verklarende woordenlijst'


    I was "playing" with xslt to achieve this but my xslt knowledge..........
    I've put the bodytext in a variable:
    [code][/code]

    and to get all subnodes from 'Verklarende woordenlijst' I had:
    [code][/code]

    To start I had for example:
    [code][/code]
    where I would change 'aanpassen' bij $Woordenlijst but that won't work because $Woordenlijst doesn't break up the nodes as seperate variables.........Any help on this will highly be appreciated!! I probarly starting of wrongly with my XSLT but if someone can put me in the right direction?! #-o

  • Arjan den Boer 76 posts 31 karma points
    Feb 03, 2009 @ 19:25
    Arjan den Boer
    0

    I think you have to do it this way: (didn't test it though)

    [code][/code]

    A step closer to your finale solution would be: (though this only works for 1 hit per $getBodyText...)

    [code][/code]

    Maybe you have to put string() around the elements in the contains() and Replace() if you get an error otherwise. As said I didn't test it.

  • Chris 110 posts 21 karma points
    Feb 04, 2009 @ 10:07
    Chris
    0

    Great work Arjan! Almost there........=d>
    Right now I have this for XSLT:
    [code]
    ]>

    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">










    [/code]

    The way it goes now that it repeats the bodyText for every node under id/1075 (4 right now). I've tright (position):
    [code][/code]

    and the bodytext is shown 1 time but nothing within the bodytext that contains a name from the 'Woordenlijst' nodes is replaced......

    Another thing is that I don't understand what you mean with putting string() around certain elements....8-[

    Any ideas?!
    Chris

  • Arjan den Boer 76 posts 31 karma points
    Feb 07, 2009 @ 22:12
    Arjan den Boer
    0

    Yes it is not very easy to modify a variable value in a loop in XSLT. I guess you will have to make a recursive xsl:template.

    Another solution would be to use regular expressions:

    First put al of your Verklarende woordenlijst items in a string variable seperated by | so it wil look like "Nodename 1|Nodename 2|Nodename 3" etc.

    [code]


    [/code]

    This example is not ready to use because it has no solution for the href part of the anchors (it just puts the nodename there for now).

    In order to use exslt regexps put xmlns:exslt.regexp="urn:Exslt.ExsltRegularExpressions" in your xsl:stylesheet.

    Could be there is a max length for the regular expression so I don't know if this is the way to go.

    You will also have to pevent that anchors are generated within anchors which will break your html.

    Maybe the best thing in terms of flexibillity and performance is not to use a XSLT macro but a C# usercontrol to make your automatic links.

Please Sign in or register to post replies

Write your reply to:

Draft