469,616 Members | 1,652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Including XSLT/XML document within a XSLT document

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

Dec 11 '05 #1
4 1511
da*******@hotmail.com wrote:
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
--
XML FAQ: http://xml.silmaril.ie/

Dec 11 '05 #2
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

Dec 12 '05 #3
da*******@hotmail.com wrote:
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, right choice. Look at <xsl:number level="multiple" format="1.1.1"/>
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
--
XML FAQ: http://xml.silmaril.ie/
Look also at the XSL List at www.mulberrytech.com for the XSL FAQ.
Dec 12 '05 #4
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:otherwise>
<xsl:attribute name="class">subclass</xsl:attribute>
</xsl:otherwise>
</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

Dec 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by tfsquare | last post: by
reply views Thread by alex | last post: by
1 post views Thread by Claudio Jolowicz | last post: by
5 posts views Thread by Per Johansson | last post: by
reply views Thread by Christopher M. Lauer | last post: by
4 posts views Thread by =?Utf-8?B?REZC?= | last post: by
3 posts views Thread by super.raddish | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.