Including XSLT/XML document within a XSLT document

D

dar_imiro

Hi,

I'm trying to get rid of frames as menu holder in my html-page. I'd
also like to separate the menu structure to xml and xslt. Also the
actual content is divided to xml and its corresponding stylesheet.

The idea ofcourse is to import the separate menu.xml to the
content.xslt file so the menu markup wont clutter every content.xml
page.

I can do it by just including the menu as html in the content.xslt file
or a separate imported xslt file, but how on earth could i also
describe my menu as xml? I dont have a script-capable server, just
static files.

Regards,

Imiro
 
P

Peter Flynn

Hi,

I'm trying to get rid of frames as menu holder in my html-page. I'd
also like to separate the menu structure to xml and xslt. Also the
actual content is divided to xml and its corresponding stylesheet.

The idea of course is to import the separate menu.xml to the
content.xslt file so the menu markup wont clutter every content.xml
page.
Right.

I can do it by just including the menu as html in the content.xslt
file or a separate imported xslt file, but how on earth could i also
describe my menu as xml? I dont have a script-capable server, just
static files.

If you have a menu.xml, you can open it and process all or part of it
in your mail XSLT stylesheet using the document() function.

<menu>
<main>
<item uri="foo">some label</item>
<item uri="bar">another label</item>
</main>
<special>
<item uri="blort">something else</special>
<item uri="splat">yet another</special>
</special>
</menu>

Then in your main XSLT something like:

<xsl:apply-templates select="document('main.xml')/menu/main"/>

<xsl:template match="main">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>

<xsl:template match="item">
<li>
<a href="{@uri}">
<xsl:apply-templates/>
</a>
</li>
</xsl:template>

I don't understand your question about scripts. They are not involved.

///Peter
 
D

dar_imiro

Thanks for the reply Peter and nice website by the way (if using IE)
:)

Allthough all my time's gone so far designing some details in the
menu.xslt and haven't had the chance to test you're example, I'm sure
it works. But then to make things complicated, I'd like to try and have
distinct stylesheets for the menu and the content. Now that I've delved
a bit more in the XSL-world (couple days hehe) it looks like it could
be done too, just import the menu.xslt in the main.xslt and use the
document() -function for the menu.xml. Atleast I'm hoping this will
work.

An other question I didn't find an answer to is how to get the depth of
the current element in the corresponding template? This is roughly my
xml:

<menu>
<item name="1"/>
<item name="2">
<item name="2.1"/>
<item name="2.2">
<item name="2.2.1"/>
...
</item>
</item>
<item name="3"/>
<menu>

Here the name-attribute has the structure and order info, but I'd like
to avoid that and get it automatically.

In the final html-rendition i need to create an id-attribute
corresponding to these items location in the menu-tree. For html-level
implementation reasons the items will be flat and the structure needs
to be maintained otherwise.

Anyway it would be very helpful to be able to recursively traverse the
items in the xsl-template and write the depth of the current node to
the rendition. How to do this? So far my best idea is to use the
ancestor::item together with xsl:param, not there yet though :p

And the server-script thingy was just incase some body would suggest to
use script like jsp/asp/php...

--Imiro
 
P

Peter Flynn

Thanks for the reply Peter and nice website by the way (if using IE)

Thanks...actually the design is homebrew and I'm no designer, and I'd
been told it doesn't look well in IE..nice to know it works somewhere!
Allthough all my time's gone so far designing some details in the
menu.xslt and haven't had the chance to test you're example, I'm sure
it works. But then to make things complicated, I'd like to try and
have distinct stylesheets for the menu and the content.

You certainly can, but you don't need to. It's perfectly possible to
have templates for elements from different document types in the one
XSLT file. But if you want to keep them separate, you can include one
in the other at runtime with <xsl:include...
Now that I've
delved a bit more in the XSL-world (couple days hehe) it looks like it
could be done too, just import the menu.xslt in the main.xslt and use
the document() -function for the menu.xml. Atleast I'm hoping this
will work.

Yes, that's what I use for my blog, for example, to get a link menu
down the LH side from a separate file.
An other question I didn't find an answer to is how to get the depth
of
the current element in the corresponding template? This is roughly my
xml:

<menu>
<item name="1"/>
<item name="2">
<item name="2.1"/>
<item name="2.2">
<item name="2.2.1"/>
...
</item>
</item>
<item name="3"/>
<menu>

Here the name-attribute has the structure and order info, but I'd like
to avoid that and get it automatically.

Yep said:
In the final html-rendition i need to create an id-attribute
corresponding to these items location in the menu-tree. For html-level
implementation reasons the items will be flat and the structure needs
to be maintained otherwise.

<xsl:attribute name="id">
<xsl:text>N.</xsl:text>
<xsl:number count="item" level="multiple" format="1.1.1"/>
</xsl:attribute>

will produce an ID attribute N.1, N.2, N.2.1, N.2.2 etc
Anyway it would be very helpful to be able to recursively traverse the
items in the xsl-template and write the depth of the current node to
the rendition. How to do this? So far my best idea is to use the
ancestor::item together with xsl:param, not there yet though :p

xsl:number is your friend.
And the server-script thingy was just incase some body would suggest
to use script like jsp/asp/php...

<gag class="spit"/> :)

///Peter
 
D

dar_imiro

Oh my, so it could be done with that tiny piece of markup ... but being
a little impatient i came up with some template trickery (which i'm
very proud of at this point;-) Hope it serves as an syntax example for
other newbs if nothing else:

<xsl:template name="item" match="item">
<xsl:param name="depth" select="0"/>
<xsl:param name="id" select="position()"/>
<xsl:text>, link=</xsl:text>
<a>
<xsl:attribute name="id">
folder<xsl:number value="$id"/>
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="count(child::item) &gt; 0">
<xsl:attribute name="onClick">shootEvent(this)</xsl:attribute>
<xsl:attribute name="class">mainclass</xsl:attribute>
</xsl:when>
<xsl:eek:therwise>
<xsl:attribute name="class">subclass</xsl:attribute>
</xsl:eek:therwise>
</xsl:choose>
<xsl:value-of select="@name"/>
</a>
<xsl:for-each select="child::item">
<xsl:call-template name="item">
<xsl:with-param name="depth" select="$depth + 1" />
<xsl:with-param name="id" select="concat(string($id), '.',
string(position()))" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>

Does the same thing than the xsl:number with more effort, but might not
be entirely worthless since there i can access some variables more
easily if need be. No doubt i can get the same result more "elegantly",
but this seems to work good :)

Thanks again for the advice, the learning curve is pretty steep with
all the XSL stuff!

I'll have to check the mullberry site more thoroughly with better time.

--Imiro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top