Calling xslt macro from xslt macro Options
Hendy Racher
Posted: Monday, May 12, 2008 11:42:48 PM
Rank: Newbie

Joined: 7/5/2007
Posts: 21
Hi,

What's the best way of being able to re-use xslt ?

For example if I have an xsl template like that found at : http://code.techinterviews.com/xslt-to-strip-html/26 to strip out html tags, what's the best way to be able to use this in a number of macros, without having to duplicate it each time ?

Many thanks,
drobar
Posted: Tuesday, May 13, 2008 1:56:05 AM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,541
Location: KY, USA
Hi, Hendy,

Here's how you include one xslt file in another...
1. Create an xslt file that has named templates that you want to re-use (this is kind of like an include file of function in other languages). Save the xslt file in umbraco just like any other. Let's call it "stripHTML.xslt" for this example.

2. Include the xslt file in other xslt files by using the following statement:
Code:
<xsl:include href="stripHTML.xslt"/>


3. Call the templates in the other included xslt in the same way you would if they were in the current xslt file itself (<xsl:call-template name="foobar">)

That's it!

Now, to your specific issue of stripping HTML... umbraco provides a function for that called umbraco.library:StripHtml(). You can find all the additional functions available to your xslt files by:

1. In the umbraco xslt editor, click the "insert value-of" icon on the toolbar.
2. In the dialog that appears, click the "get extensions" button.
3. In the dialog that appears, select "umbraco.library" from the drop-down list, then you'll be able to select the various functions available.

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
Hendy Racher
Posted: Tuesday, May 13, 2008 7:30:47 AM
Rank: Newbie

Joined: 7/5/2007
Posts: 21
Fantastic, wasn't aware of the umbraco.library:StripHtml() function, does exactly what I need.
Hendy Racher
Posted: Thursday, May 22, 2008 3:38:13 PM
Rank: Newbie

Joined: 7/5/2007
Posts: 21
If I have an xslt macro defined with parameters, is it possible to call this from another xslt and be able to pass in the parameters ? or should xslt macros only be called from umbraco tempalates ? Hope this makes sense, TIA.
drobar
Posted: Thursday, May 22, 2008 4:14:30 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,541
Location: KY, USA
Calling from templates or the rich text editor is the best approach, but you can try the umbraco.library:RenderMacro() call. Or you can use the xsl:include function noted above.

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.