473,769 Members | 5,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

including one XML file in another XML file

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?

Here is exactly what I'm trying to do:

design.xml:
<?xml .....>
<root>
<design>....</design>
<library>.... </library>
</root>

Currently the 'library' element is inside the 'design.xml' file. I
want to put the library element into a separate xml file and include
it in all my design files. (I have a lot of designs and only a couple
of libraries).

The design.xml file contains a reference to an XSLT file that
visualizes the design. When you open the design.xml file in Firefox a
SVG (scalable vector graphics) file is created on the fly and shown to
you.

I also have an XML Schema file that specifies what all the valid
elements in the design.xml file are.

Can someone show me an example that accomplishes this? That would be
great.

thanks, Johan.

Feb 21 '07 #1
20 3154
How can I include one XML file into another XML file (on the client
side, in Firefox)?
I'm kind of new to XML, but let me take a stab at answering this.
Depending on what you want the client to do with the document, it
seems you might be able to accomplish this at the stylesheet level
using document().

design.xml
<?xml ...>
<root>
<design... </design>
<library/>
</root>

library.xml
<?xml ...>
<library>
....
</library>

stylesheet.xml
<?xml version="1.0">
<xsl:styleshe et ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="documen t(library.xml)/"/>
</xsl:template>
</xsl:stylesheet>

I might not have the syntax quite right, but I hope you get the idea.
When the stylesheet is applied to design.xml, the processor will
access and handle the external file as if it were part of the source
document. For further info see the XSL section on handling multiple
documents: http://www.w3.org/TR/xslt#document

Good luck!

Feb 21 '07 #2
On Feb 21, 11:45 am, "Johan" <joh...@gmail.c omwrote:
design.xml:
<?xml .....>
<root>
<design>....</design>
<library>.... </library>
</root>

Currently the 'library' element is inside the
'design.xml' file. I want to put the library element into
a separate xml file and include it in all my design
files. (I have a lot of designs and only a couple of
libraries).

The design.xml file contains a reference to an XSLT file
that visualizes the design.
I don't believe what you want is possible, but there are
other solutions to the problem; document() on the XSLT side
in particular comes to mind. Proof-of-concept:

xform1.xml:

<?xml-stylesheet type="text/xsl" href="xform.xsl "?>
<root library="1">
<design>1</design>
</root>

xform_lib_1.xml :

<library>
<design n="1">A</design>
</library>

xform.xsl:

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="lib"
select=
"
document(concat ('xform_lib_',/root/@library,'.xml' ))
"/>
<xsl:template match="root">
<result>
<xsl:apply-templates/>
</result>
</xsl:template>
<xsl:template match="design">
<xsl:value-of
select="$lib/library/design[@n=current()]"/>
</xsl:template>
</xsl:stylesheet>

Note that client-side transformations in general should be
avoided, unless you know very well what you're doing. So,
unless you know very well what you're doing, consider
transforming your document server-side.

--
Pavel Lepin

Feb 21 '07 #3
On 21 feb, 11:11, "fildpauz" <fildp...@gmail .comwrote:
How can I include one XML file into another XML file (on the client
side, in Firefox)?

I'm kind of new to XML, but let me take a stab at answering this.
Depending on what you want the client to do with the document, it
seems you might be able to accomplish this at the stylesheet level
using document().

design.xml
<?xml ...>
<root>
<design... </design>
<library/>
</root>

library.xml
<?xml ...>
<library>
...
</library>

stylesheet.xml
<?xml version="1.0">
<xsl:styleshe et ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="documen t(library.xml)/"/>
</xsl:template>
</xsl:stylesheet>

I might not have the syntax quite right, but I hope you get the idea.
When the stylesheet is applied to design.xml, the processor will
access and handle the external file as if it were part of the source
document. For further info see the XSL section on handling multiple
documents:http://www.w3.org/TR/xslt#document
Thanks for this explanation. I only have one question remaining:
How can I perform xsl:apply-templates to the union of the design and
the library together?
(There aren't any templates that directly match elements in the
library. There template that matches the design element gets values
from the library when it needs them (using <xsl:variable name="..."
select="...">).

Johan.

Feb 21 '07 #4
Thanks for this explanation. I only have one question remaining:
How can I perform xsl:apply-templates to the union of the design and
the library together?
(There aren't any templates that directly match elements in the
library. There template that matches the design element gets values
from the library when it needs them (using <xsl:variable name="..."
select="...">).
Unless you have some reason not to do so, you can put templates that
apply to the library nodes in the same stylesheet. Alternatively you
can put those templates in an independent stylesheet and include it in
the main stylesheet using xsl:include (http://www.w3.org/TR/
xslt#section-Combining-Stylesheets). However, I have a feeling that a
proper solution to this problem would involve namespaces but that is
getting beyond my (in)expertise.

Cheers,
fildpauz

Feb 21 '07 #5
On 21 feb, 12:41, "fildpauz" <fildp...@gmail .comwrote:
Thanks for this explanation. I only have one question remaining:
How can I perform xsl:apply-templates to the union of the design and
the library together?
(There aren't any templates that directly match elements in the
library. There template that matches the design element gets values
from the library when it needs them (using <xsl:variable name="..."
select="...">).

Unless you have some reason not to do so, you can put templates that
apply to the library nodes in the same stylesheet. Alternatively you
can put those templates in an independent stylesheet and include it in
the main stylesheet using xsl:include (http://www.w3.org/TR/
xslt#section-Combining-Stylesheets). However, I have a feeling that a
proper solution to this problem would involve namespaces but that is
getting beyond my (in)expertise.
I don't have templates that match the library nodes. I only have
templates for the design. These templates 'get' a value from the
library when they need it (with xsl:variable).
So
<xsl:apply-templates select="documen t(library.xml)/"/>
doesn't match anything. That's why I want to call 'apply-templates'
and 'select' both the design and the library at the same time. So I
want the union of "design" and "document(libra ry.xml)". Is there a way
to do this?

Feb 21 '07 #6
On 21 feb, 11:30, p.le...@ctncorp .com wrote:
On Feb 21, 11:45 am, "Johan" <joh...@gmail.c omwrote:
design.xml:
<?xml .....>
<root>
<design>....</design>
<library>.... </library>
</root>
Currently the 'library' element is inside the
'design.xml' file. I want to put the library element into
a separate xml file and include it in all my design
files. (I have a lot of designs and only a couple of
libraries).
The design.xml file contains a reference to an XSLT file
that visualizes the design.

I don't believe what you want is possible, but there are
other solutions to the problem; document() on the XSLT side
in particular comes to mind. Proof-of-concept:

xform1.xml:

<?xml-stylesheet type="text/xsl" href="xform.xsl "?>
<root library="1">
<design>1</design>
</root>

xform_lib_1.xml :

<library>
<design n="1">A</design>
</library>

xform.xsl:

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="lib"
select=
"
document(concat ('xform_lib_',/root/@library,'.xml' ))
"/>
<xsl:template match="root">
<result>
<xsl:apply-templates/>
</result>
</xsl:template>
<xsl:template match="design">
<xsl:value-of
select="$lib/library/design[@n=current()]"/>
</xsl:template>
</xsl:stylesheet>

Note that client-side transformations in general should be
avoided, unless you know very well what you're doing. So,
unless you know very well what you're doing, consider
transforming your document server-side.
Thanks for your help, but there is one part that I don't understand:
<xsl:template match="design">
<xsl:value-of
select="$lib/library/design[@n=current()]"/>
</xsl:template>

I think "xsl:value-of" element selects the value of the library/
design[n] element and add it to the output. Is that right? (I don't
want to do that).

I will describe my problem in a little bit more detail:
The <libraryeleme nt contains one or more <typeelements . Each type
has an "id" attribute.
The author of the design.xml file can use type's from the library by
referring to their id.

Both the design and library (with all the types) used to be in the
same file, but now I want to put the <librarywith all the <type>'s
in a separate file.
Feb 21 '07 #7
On 21 feb, 12:06, "Johan" <joh...@gmail.c omwrote:
On 21 feb, 11:11, "fildpauz" <fildp...@gmail .comwrote:
How can I include one XML file into another XML file (on the client
side, in Firefox)?
I'm kind of new to XML, but let me take a stab at answering this.
Depending on what you want the client to do with the document, it
seems you might be able to accomplish this at the stylesheet level
using document().
design.xml
<?xml ...>
<root>
<design... </design>
<library/>
</root>
library.xml
<?xml ...>
<library>
...
</library>
stylesheet.xml
<?xml version="1.0">
<xsl:styleshe et ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="documen t(library.xml)/"/>
</xsl:template>
</xsl:stylesheet>
I might not have the syntax quite right, but I hope you get the idea.
When the stylesheet is applied to design.xml, the processor will
access and handle the external file as if it were part of the source
document. For further info see the XSL section on handling multiple
documents:http://www.w3.org/TR/xslt#document

Thanks for this explanation. I only have one question remaining:
How can I perform xsl:apply-templates to the union of the design and
the library together?
(There aren't any templates that directly match elements in the
library. There template that matches the design element gets values
from the library when it needs them (using <xsl:variable name="..."
select="...">).

Johan.
For clarification:
P.S. I want to 'include' the library.xml file into the design.xml file
before the XSLT processing happens (or at the start of the XSLT
processing before processing the <designelement) .

P.S. #2. I have to use client-side processing. Local users should be
able to edit the design.xml file and visualize it in Firefox. If I
could use server side processing I could use XInclude.

Johan.
Feb 21 '07 #8
On Feb 21, 2:14 pm, "Johan" <joh...@gmail.c omwrote:
On 21 feb, 11:30, p.le...@ctncorp .com wrote:
On Feb 21, 11:45 am, "Johan" <joh...@gmail.c omwrote:
design.xml:
<?xml .....>
<root>
<design>....</design>
<library>.... </library>
</root>
Currently the 'library' element is inside the
'design.xml' file. I want to put the library element
into a separate xml file and include it in all my
design files. (I have a lot of designs and only a
couple of libraries).
The design.xml file contains a reference to an XSLT
file that visualizes the design.
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="lib"
select=
"
document(concat ('xform_lib_',/root/@library,'.xml' ))
"/>
<xsl:template match="root">
<result>
<xsl:apply-templates/>
</result>
</xsl:template>
<xsl:template match="design">
<xsl:value-of
select="$lib/library/design[@n=current()]"/>
</xsl:template>
</xsl:stylesheet>

there is one part that I don't understand:
<xsl:template match="design">
<xsl:value-of
select="$lib/library/design[@n=current()]"/>
</xsl:template>

I think "xsl:value-of" element selects the value of the
library/design[n] element and add it to the output. Is
that right?
No, it selects a design element that has the n attribute
with the value equal to the value of the current node.
(I don't want to do that).
>From your explanations it actually sounds to me as if
that's more or less what you want to do.
I will describe my problem in a little bit more detail:
The <libraryeleme nt contains one or more <type>
elements. Each type has an "id" attribute. The author of
the design.xml file can use type's from the library by
referring to their id.
Depending on exact way the author may 'use' the types from
the library, this might look similar to the following:

<xsl:template match="refer-to-lib-type">
<xsl:apply-templates
select="$lib/library/type[@id=current()/@id]"/>
</xsl:template>

The XML files would look like this:

<root library="librar y-identifier">
<design>
<refer-to-lib-type id="type-id-example"/>
</design>
</root>

<library>
<type id="type-id-example">
<whatever-needs-to-be-processed/>
</type>
</library>

--
Pavel Lepin

Feb 21 '07 #9
On 21 feb, 13:51, p.le...@ctncorp .com wrote:
On Feb 21, 2:14 pm, "Johan" <joh...@gmail.c omwrote:
On 21 feb, 11:30, p.le...@ctncorp .com wrote:
On Feb 21, 11:45 am, "Johan" <joh...@gmail.c omwrote:
design.xml:
<?xml .....>
<root>
<design>....</design>
<library>.... </library>
</root>
Currently the 'library' element is inside the
'design.xml' file. I want to put the library element
into a separate xml file and include it in all my
design files. (I have a lot of designs and only a
couple of libraries).
The design.xml file contains a reference to an XSLT
file that visualizes the design.
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="lib"
select=
"
document(concat ('xform_lib_',/root/@library,'.xml' ))
"/>
<xsl:template match="root">
<result>
<xsl:apply-templates/>
</result>
</xsl:template>
<xsl:template match="design">
<xsl:value-of
select="$lib/library/design[@n=current()]"/>
</xsl:template>
</xsl:stylesheet>
there is one part that I don't understand:
<xsl:template match="design">
<xsl:value-of
select="$lib/library/design[@n=current()]"/>
</xsl:template>
I think "xsl:value-of" element selects the value of the
library/design[n] element and add it to the output. Is
that right?

No, it selects a design element that has the n attribute
with the value equal to the value of the current node.
(I don't want to do that).
From your explanations it actually sounds to me as if

that's more or less what you want to do.
I will describe my problem in a little bit more detail:
The <libraryeleme nt contains one or more <type>
elements. Each type has an "id" attribute. The author of
the design.xml file can use type's from the library by
referring to their id.

Depending on exact way the author may 'use' the types from
the library, this might look similar to the following:

<xsl:template match="refer-to-lib-type">
<xsl:apply-templates
select="$lib/library/type[@id=current()/@id]"/>
</xsl:template>

The XML files would look like this:

<root library="librar y-identifier">
<design>
<refer-to-lib-type id="type-id-example"/>
</design>
</root>

<library>
<type id="type-id-example">
<whatever-needs-to-be-processed/>
</type>
</library>
I don't have templates that match the library (or the types inside
it), so
<xsl:apply-templates
select="$lib/library/type[@id=current()/@id]"/>
isn't going to match anything.

I think the solution from fildpauz fits my needs the best:

stylesheet.xml
<?xml version="1.0">
<xsl:styleshe et ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="documen t(library.xml)/"/>
</xsl:template>
</xsl:stylesheet>

The only question that remains is this one:
"How can I perform xsl:apply-templates to the union of the design and
the library together?
(There aren't any templates that directly match elements in the
library. There template that matches the design element gets values
from the library when it needs them (using <xsl:variable name="..."
select="...">)) . "

"So I want the union of "design" and "document(libra ry.xml)". Is there
a way
to do this?"

Feb 21 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2297
by: hntgzr | last post by:
I am trying to include a function in a .php file on a different server from the main .php files. I am using: include_path=http://www.anotherserver.com/foldername; include(http://www.anotherserver.com/foldername/phpfiletocall.inc); The .inc file is php formatted. Variables are passed to it (not via GET or POST though) and returned using return(variablenames, etc);
5
5689
by: mayamorning123 | last post by:
A comparison among six VSS remote tools including SourceOffSite , SourceAnyWhere, VSS Connect, SourceXT, VSS Remoting, VSS.NET To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool This article makes a detailed comparison among SourceAnyWhere 4.0, SourceOffSite 4.1, VSS Connect 1.5, SourceXT 2.1, VSS Remoting 2.5,
3
2641
by: Will Chamberlain | last post by:
For the next couple of months I am hosting 2 domains with one host (Brinkster). What I have done is setup a page called default.aspx and a select case for SiteNameURL = Request.ServerVariables("SERVER_NAME"). The only way I can get this to work is to use Response.Redirect for one of the domains. I can include a file (Index.aspx) just fine for domain B. When I attempt to include a file for Domain B I get errors such as: The Connection...
8
3050
by: nrhayyal | last post by:
Hi c++ Gurus, Need your blessing. while testing few aspects with respect to header file inclusions, i observed few things which i would like to share with you. i have a file sqlca.h in which a structure sqlca is declared. i included this file as a soft link in /usr/include. the soft link is as follows: sqlca.h -> /usr/opt/db2_08_01/include64/sqlca.h
4
1677
by: dar_imiro | last post by:
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.
4
6956
by: 'Mani | last post by:
Hi, This is just a generic question, where i want to know what is the difference in including a header file in a .h file and .cpp file. I have a class called MyClass (MyClass.h & MyClass.cpp). There is another class (OtherClass.h & OtherClass.cpp) OtherClass.cpp has a forward declaration to a class called 'Calc' which is in the namespace called 'Utils' like below:
11
2812
by: Gary Wessle | last post by:
Hi is it right to have a line like #include <path/to/header.hfor a library on my system, in my header file and use some functions provided by this library in the implementation file (file.cpp) inside a class with out declaring those functions in the class declaration in the header file? thanks
38
4031
by: Neo Geshel | last post by:
I am seeking a method to load one JS file directly into another, *without* having to dynamically write <scripttags. Is there any method whereby I can call only one external JS file using a single <scripttag, but have that external JS file insert into ITSELF the contents of five others? Something like: /*start external.js*/
2
1542
by: webcm123 | last post by:
I'm making some changes in files structure in my CMS. I will use more templates for modules. However, the topic of <titleand other ... came back when i was thinking about it. ---- Pre-generating (A) ---- It uses output buffering. Modules files are included before <html>. The whole middle output (e.g. article with comment, registration form) is stored in RAM (or SWAP :D) and prepared for putting it into the main layout inside <body>....
1
2856
by: davidwelli | last post by:
Hello, I have a Access 200 format database that contains contact details and a picture for each record. The contact details are held in one table and the images are held in another as OLE Objects. This database is used to produce passes. I want to export one record from the dartabase including the picture into a format that can be easily tansferred by email. I've created a query based on the two tables that will retreive all the...
0
9589
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
9423
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
10219
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
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
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();...
1
3967
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
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.