You are not logged in.

#1 2009-01-27 17:42:05

munkyeetr
Member
From: Merritt, BC
Registered: 2008-08-07
Posts: 83

XML/XSLT: Setting xsl:include href attribute with a variable

I have a main layout stylesheet and depending on which page the user selects I want to use xsl:include to display the selected information in the 'content' DIV. The process works fine if hardcode it like this:

<xsl:include href="welcome.xsl"/>
...
<div id="content"
    <xsl:call-template name="welcome"/>
</div>

but, what I would like to do is have the name of the included template pulled from the xml file depending on which page was selected by the user. Something similar to this:

<xsl:variable name="ss">
    <xsl:text><xsl:value-of select="root/stylesheet"/></xsl:text>
</xsl:variable>

<xsl:include href="{$ss}.xsl"/>

...

<div id="content">
    <xsl:apply-template name="{$ss}"/>
</div>

So far I have tried using many different forms of code and have been unable to get this to work. Any ideas?

EDIT: Okay, I have it partly figured out, at least why it isn't working. As far as I can tell, the 'xsl:include' tag must be a child of the 'xsl:stylesheet' tag, and is thus declared before the <xsl:template match="/"> which means it can't read the xml element to even store it in the variable. I have an idea of how to accomplish what I need, though. tongue

Last edited by munkyeetr (2009-01-28 03:29:58)


If the advice you're given in this forum solves your issue, please mark the post as [SOLVED] in consideration to others.

"More than any time in history mankind faces a crossroads. One path leads to despair and utter hopelessness, the other to total extinction.
Let us pray that we have the wisdom to choose correctly." -- Woody Allen

Offline

Board footer

Powered by FluxBB