473,652 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1662
da*******@hotma il.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">anoth er label</item>
</main>
<special>
<item uri="blort">som ething else</special>
<item uri="splat">yet another</special>
</special>
</menu>

Then in your main XSLT something like:

<xsl:apply-templates select="documen t('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*******@hotma il.com wrote:
Thanks for the reply Peter and nice website by the way (if using IE)
Thanks...actual ly 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:attribut e 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="positio n()"/>
<xsl:text>, link=</xsl:text>
<a>
<xsl:attribut e name="id">
folder<xsl:numb er value="$id"/>
</xsl:attribute>
<xsl:attribut e name="href">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="count(chi ld::item) &gt; 0">
<xsl:attribut e name="onClick"> shootEvent(this )</xsl:attribute>
<xsl:attribut e name="class">ma inclass</xsl:attribute>
</xsl:when>
<xsl:otherwis e>
<xsl:attribut e name="class">su bclass</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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2502
by: tfsquare | last post by:
All, I am new to XSLT and having some problems understanding the syntax of XPath which selects nodes in the XML document. Consider this bit of XML, which contains three outer XML elements. <FOO>foo.top.level</FOO> <BOO><FOO>foo.second.level</FOO></BOO> <CHOO><BOO><FOO>foo.third.level</FOO></BOO></CHOO>
0
1597
by: alex | last post by:
I'm new to xslt, and I am attempting to use it to produce a comma-separated-value file from a large, dynamically-generated data file formatted in xml (examples of the xml file and my xslt style sheet follow). It works pretty well, but xsltproc takes an extremely long time to process the data file when it grows fairly large (>1MB). I've read that using keys can improve processing time on large documents, however I don't know the number of...
1
2021
by: Claudio Jolowicz | last post by:
I need to produce an HTML page with javascript using XSLT. Unfortunately, Mozilla has a bug that lets it crash when it encounters document.write in an XSLT stylesheet (bugzilla# 202765). Are there XSLT-related workarounds to this bug? I am aware that mozilla bug discussions are off-topic on this list. This question concerns only possible alternatives making use of XSLT's facilities. Neither linking to an external javascript file, nor...
5
16877
by: Per Johansson | last post by:
Is it possible to use XSLT to automatically create href links while it formats an XML document? That is, if it finds "http://me.us/" in a text, it adds <a href="http://me.us/">http://me.us/</a> -- Per Johansson Systems developer http://per.johansson.name/
0
2342
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag, such as a div with a runat=server. I can somewhat do this if I create a server control and include the control within the html div tag but this method (borrowed from ASP.NET Website Programming by Wrox press thanks guys) does not give me the full...
3
4825
by: Gordon Moore | last post by:
Hi, I'm new to using xml/xslt and although I can create an xml document using the dataset.WriteXml statement, and I have created an xslt to transform the xml into the output I want, I have to manually add the xsl reference statement to the xml file. i.e. <?xml version="1.0" standalone="yes"?> <?xml:stylesheet type="text/xsl" href="Questions.xsl"?> --> I have to
4
4303
by: =?Utf-8?B?REZC?= | last post by:
Within an XSLT transformation, I'm trying to switch the default namespace within a section of the generated XML document to a shared namespace. This way, the content of this section does not have to use a prefix for the shared namespace, thus making the document smaller and easier to read. This worked in .NET 1.1 with no problem, but now appears to be broken in 2.0. When you try to do this, the following XslTransformException is...
20
3142
by: Johan | last post by:
How can I include one XML file into another XML file (on the client side, in Firefox)? I think XInclude is just what I need, but Firefox doesn't support it: https://bugzilla.mozilla.org/show_bug.cgi?id=201754 It seems I also can use an "external entity reference", but that depends on a DTD and I'm using XML Schema. Is it also possible with a Schema and how can I do it?
3
9582
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.