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

Joined: 7/5/2007
Posts: 26
Location: UK
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,831
Location: MA, 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 - Percipient Studios
Hendy Racher
Posted: Tuesday, May 13, 2008 7:30:47 AM
Rank: Enthusiast

Joined: 7/5/2007
Posts: 26
Location: UK
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: Enthusiast

Joined: 7/5/2007
Posts: 26
Location: UK
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,831
Location: MA, 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 - Percipient Studios
rvalencia
Posted: Tuesday, November 25, 2008 2:12:49 AM

Rank: Newbie

Joined: 10/18/2008
Posts: 8
Location: mexico
Hi Guys, Im in trouble Brick wall in umbraco 3, let me explain.
i have a template which calls a xslt macro, inside the xslt im trying to use the umbraco.library:RenderMacro() and send some params by using the technique refered by
"Passing parameters to RenderMacroContent"
in the debug view i see in red "macro.loadControlProperties Property added 'pageId' with value '1070' " i guess the issue is having a macro being rendered inside a macro.

I hope I made my self clear.
its weird because if i call the macro from the template (not inside the xslt) it renders fine
thanks for your suggests
Ricardo
imayat12
Posted: Tuesday, November 25, 2008 11:06:21 AM

Rank: Addict

Joined: 7/19/2006
Posts: 670
Location: Preston, UK
Ricardo,

You can call xslt macro from xslt macro can you paste your code for both macros so we can investigate further.

Regards

Ismail

Level 2 certified. If it aint broke dont fix.
rvalencia
Posted: Tuesday, November 25, 2008 5:34:37 PM

Rank: Newbie

Joined: 10/18/2008
Posts: 8
Location: mexico
i guess that is the problem:
the container macro is an xslt macro and the one getting the red lines in the debug view is a .net control macro.
- the container macro is rendering some blog content feeded by umbraco data
- the child macro is rendering the total posts count for each blog and its feeded by a custom table in a separate db.

ill paste the code once i get to my work place.
rvalencia
Posted: Tuesday, November 25, 2008 5:44:55 PM

Rank: Newbie

Joined: 10/18/2008
Posts: 8
Location: mexico
Hi Ismail
I've found some more documentation about this issue here
ill try to create an xslt extension for this.
thanks!
Ricardo
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.