473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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 3099
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:stylesheet ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="document(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.comwrote:
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:stylesheet 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:stylesheet ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="document(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="document(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(library.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.comwrote:
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:stylesheet 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 <libraryelement 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.comwrote:
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:stylesheet ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="document(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.comwrote:
On 21 feb, 11:30, p.le...@ctncorp.com wrote:
On Feb 21, 11:45 am, "Johan" <joh...@gmail.comwrote:
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:stylesheet 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 <libraryelement 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="library-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.comwrote:
On 21 feb, 11:30, p.le...@ctncorp.com wrote:
On Feb 21, 11:45 am, "Johan" <joh...@gmail.comwrote:
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:stylesheet 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 <libraryelement 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="library-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:stylesheet ... >
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="document(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(library.xml)". Is there
a way
to do this?"

Feb 21 '07 #10
On Feb 21, 3:43 pm, "Johan" <joh...@gmail.comwrote:
On 21 feb, 13:51, p.le...@ctncorp.com wrote:
On Feb 21, 2:14 pm, "Johan" <joh...@gmail.comwrote:
On 21 feb, 11:30, p.le...@ctncorp.com wrote:
<xsl:stylesheet 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>
I will describe my problem in a little bit more
detail: The <libraryelement 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.
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>
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.
Create the templates to match the library elements, then.
It's good design anyway.
I think the solution from fildpauz fits my needs the
best:

<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="document(library.xml)/"/>
</xsl:template>
You don't seem to understand how this solution would work.
As you yourself said, you don't have any templates that
would match the elements within your library, so
apply-templates select="document('library.xml')" would
merely apply the default templates to this nodeset.
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?
You cannot achieve the results identical to using XInclude,
period. You may attempt to do something like

<xsl:variable
name="everything" select="/|document('foo')"/>

but even if it works for you, I doubt it would really solve
your problems. You seem to be way over your head as it is,
and if you try juggling nodesets without accidentally
converting them to rtfs and ending you days in an asylum
due to the sheer frustration of it, you're bound to drown.
(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 believe I explained to you how to write XPath
expressions accessing other documents, it doesn't matter
whether you use them to apply templates, grab values or
populate variables. Either you want to do it the easy way
(in that case, deal with it--there's no easy way short of
XSLT2, and no, existing browsers do not support that) or
you don't really understand what's going on (and in that
case perhaps you should stop tinkering with real projects
before you break something, and start tinkering with toy
projects).

--
Pavel Lepin

Feb 21 '07 #11
On 21 feb, 15:28, p.le...@ctncorp.com wrote:
On Feb 21, 3:43 pm, "Johan" <joh...@gmail.comwrote:
On 21 feb, 13:51, p.le...@ctncorp.com wrote:
On Feb 21, 2:14 pm, "Johan" <joh...@gmail.comwrote:
On 21 feb, 11:30, p.le...@ctncorp.com wrote:
<xsl:stylesheet 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>
I will describe my problem in a little bit more
detail: The <libraryelement 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.
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>
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.

Create the templates to match the library elements, then.
It's good design anyway.
It's not that simple. There is no direct relation between the elements
in the library and the resulting SVG xml file.
The design xml file is leading. It only refers to the library for
looking up values from different types.
I think the solution from fildpauz fits my needs the
best:
<xsl:template match="root">
<xsl:apply-templates select="design"/>
<xsl:apply-templates select="document(library.xml)/"/>
</xsl:template>

You don't seem to understand how this solution would work.
As you yourself said, you don't have any templates that
would match the elements within your library, so
apply-templates select="document('library.xml')" would
merely apply the default templates to this nodeset.
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?

You cannot achieve the results identical to using XInclude,
period. You may attempt to do something like

<xsl:variable
name="everything" select="/|document('foo')"/>
I will try that, thanks.
but even if it works for you, I doubt it would really solve
your problems. You seem to be way over your head as it is,
and if you try juggling nodesets without accidentally
converting them to rtfs and ending you days in an asylum
due to the sheer frustration of it, you're bound to drown.
(see reaction below).
(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 believe I explained to you how to write XPath
expressions accessing other documents, it doesn't matter
whether you use them to apply templates, grab values or
populate variables. Either you want to do it the easy way
(in that case, deal with it--there's no easy way short of
XSLT2, and no, existing browsers do not support that) or
you don't really understand what's going on (and in that
case perhaps you should stop tinkering with real projects
before you break something, and start tinkering with toy
projects).
FYI, this is a real project and all I'm doing is making a small change
(I hope).
After all, the equivalent XInclude solution is really simple (but not
working in Firefox).
I just don't have the time to rebuild the complete XSLT file and also
it's already a pretty complex one. All I want to do is put the
<libraryelement in another xml file. I understand your opinion: it's
bad/evil to hack this into the stylesheet, but in the real world there
are practical factors that I don't have control over.

Yes, I can start learning XSLT, XPath, XSchema, etc and rebuild the
whole thing, but that is going to take months and I just don't have
that time.

Feb 22 '07 #12
On Feb 22, 9:49 am, "Johan" <joh...@gmail.comwrote:
On 21 feb, 15:28, p.le...@ctncorp.com wrote:
On Feb 21, 3:43 pm, "Johan" <joh...@gmail.comwrote:
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?
You cannot achieve the results identical to using
XInclude, period. You may attempt to do something like
<xsl:variable
name="everything" select="/|document('foo')"/>

I will try that, thanks.
You're not listening, are you? You *won't* get the results
identical to using XInclude without XSLT2 or EXSLT. (For
that matter, it's not as trivial as you seem to think it
should be with XSLT2 or EXSLT.) Modern browsers do not
support XSLT2 or EXSLT. If you use the union, you'll have
to check and probably rewrite all of your XPath expressions
referring to the children of library elements anyway.
There's no easy way. You'll have to do that. So don't turn
it into a maintenance nightmare for the guy who will have
to work with your code after you just for the sake of using
'union'. Do it the right way. Refer directly to the
external document.
(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 believe I explained to you how to write XPath
expressions accessing other documents, it doesn't
matter whether you use them to apply templates, grab
values or populate variables. Either you want to do it
the easy way (in that case, deal with it--there's no
easy way short of XSLT2, and no, existing browsers do
not support that) or you don't really understand what's
going on (and in that case perhaps you should stop
tinkering with real projects before you break
something, and start tinkering with toy projects).

FYI, this is a real project and all I'm doing is making a
small change (I hope).
You hope, indeed. I've been trying to tell you that it's
very unlikely you'll be doing a small change. Just because
your boss wants it tomorrow and you don't want to
disappoint him doesn't yet mean it's possible. Worse yet,
it might turn out to be possible, but the 'easy' solution
might introduce subtle bugs you'll spend the rest of your
life trying to weed out.

Worse yet, you might quit and *someone else* might have to
spend the rest of his bloody life trying to weed out the
subtle bugs you've introduced with this 'solution'.
After all, the equivalent XInclude solution is really
simple (but not working in Firefox).
Using fork(2) is really simple. Try implementing it in
bare-bones Lisp.
I just don't have the time to rebuild the complete XSLT
file and also it's already a pretty complex one.
Do you really believe wishful thinking is gonna solve your
problems? 'I don't have much time, I don't have the
expertise, but since I need it done yesterday, OF COURSE
there will be a simple solution.'
All I want to do is put the <libraryelement in another
xml file. I understand your opinion: it's bad/evil to
hack this into the stylesheet,
No, you don't. It is bad/evil to hack this into the
stylesheet, but that's not the real problem. It's just that
this hack is very unlikely to work without other changes to
the stylesheet. So you'll hack this in, find out that
something doesn't work, or worse--that something *almost*
seems to work, and you'll try to fix this and that and the
other thing, and you'll end up going over all of your XPath
expressions anyway, and you'll get it working in the end,
the difference being that this idiotic hack will still be
in the code, while you could've done the same thing the
right way from the start.

I won't mention the fact that incremental problem-fixing is
likely to turn the code into the cockroach farm where
angels fear to tread.
but in the real world there are practical factors that I
don't have control over.
Invoking 'practical factors... don't have control...'
rarely solves problems.

--
Pavel Lepin

Feb 22 '07 #13
On 22 feb, 09:51, p.le...@ctncorp.com wrote:
On Feb 22, 9:49 am, "Johan" <joh...@gmail.comwrote:
On 21 feb, 15:28, p.le...@ctncorp.com wrote:
On Feb 21, 3:43 pm, "Johan" <joh...@gmail.comwrote:
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?
You cannot achieve the results identical to using
XInclude, period. You may attempt to do something like
<xsl:variable
name="everything" select="/|document('foo')"/>
I will try that, thanks.

You're not listening, are you? You *won't* get the results
identical to using XInclude without XSLT2 or EXSLT. (For
that matter, it's not as trivial as you seem to think it
should be with XSLT2 or EXSLT.) Modern browsers do not
support XSLT2 or EXSLT. If you use the union, you'll have
to check and probably rewrite all of your XPath expressions
referring to the children of library elements anyway.
I'm I listening, but from a different point of view.
I'm going to use the union and if necessary I'm going to change the
"XPath expressions referring to the children of library elements".
Although I don't understand yet what exactly I will need to change.
The union (as far as I know it from school) doesn't change it inputs,
it only merges to sets.
If you are in a good mood you might want to give me some hints about
this :)
There's no easy way. You'll have to do that. So don't turn
it into a maintenance nightmare for the guy who will have
to work with your code after you just for the sake of using
'union'. Do it the right way. Refer directly to the
external document.
Sorry, but I don't understand what you are trying to say.
How can I refer directly to the external document (without creating
templates that match the library elements, I already explained that's
not what I want).
(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 believe I explained to you how to write XPath
expressions accessing other documents, it doesn't
matter whether you use them to apply templates, grab
values or populate variables.
I think you only explained "how to write XPath expressions accessing
other documents" for use with apply-templates.
How can I use it to grap/populate variables? Could you give an
example?
You hope, indeed. I've been trying to tell you that it's
very unlikely you'll be doing a small change. Just because
your boss wants it tomorrow and you don't want to
disappoint him doesn't yet mean it's possible. Worse yet,
it might turn out to be possible, but the 'easy' solution
might introduce subtle bugs you'll spend the rest of your
life trying to weed out.

Worse yet, you might quit and *someone else* might have to
spend the rest of his bloody life trying to weed out the
subtle bugs you've introduced with this 'solution'.
After all, the equivalent XInclude solution is really
simple (but not working in Firefox).

Using fork(2) is really simple. Try implementing it in
bare-bones Lisp.
I just don't have the time to rebuild the complete XSLT
file and also it's already a pretty complex one.

Do you really believe wishful thinking is gonna solve your
problems? 'I don't have much time, I don't have the
expertise, but since I need it done yesterday, OF COURSE
there will be a simple solution.'
All I want to do is put the <libraryelement in another
xml file. I understand your opinion: it's bad/evil to
hack this into the stylesheet,

No, you don't. It is bad/evil to hack this into the
stylesheet, but that's not the real problem. It's just that
this hack is very unlikely to work without other changes to
the stylesheet. So you'll hack this in, find out that
something doesn't work, or worse--that something *almost*
seems to work, and you'll try to fix this and that and the
other thing, and you'll end up going over all of your XPath
expressions anyway, and you'll get it working in the end,
the difference being that this idiotic hack will still be
in the code, while you could've done the same thing the
right way from the start.
I don't mind changing all the XPath expressions that get values from
the <librarychild elements.
This is far more easy than changing the complete structure of the
stylesheet (eg. writing new templates that match the library
elements).

thanks for you help,
Johan.

Feb 22 '07 #14
On 22 feb, 09:51, p.le...@ctncorp.com wrote:
On Feb 22, 9:49 am, "Johan" <joh...@gmail.comwrote:
On 21 feb, 15:28, p.le...@ctncorp.com wrote:
On Feb 21, 3:43 pm, "Johan" <joh...@gmail.comwrote:
You're not listening, are you? You *won't* get the results
identical to using XInclude without XSLT2 or EXSLT. (For
that matter, it's not as trivial as you seem to think it
should be with XSLT2 or EXSLT.) Modern browsers do not
support XSLT2 or EXSLT. If you use the union, you'll have
to check and probably rewrite all of your XPath expressions
referring to the children of library elements anyway.
There's no easy way. You'll have to do that. So don't turn
it into a maintenance nightmare for the guy who will have
to work with your code after you just for the sake of using
'union'. Do it the right way. Refer directly to the
external document.
And what about the solution with external entities? See "C.27 How do
I include one XML file in another?" in the XML FAQ:
http://xml.silmaril.ie/authors/includes/

Can this be done with an XML schema in the same way?
That would be a really easy solution, right?

Johan.

Feb 22 '07 #15
On Feb 22, 12:34 pm, "Johan" <joh...@gmail.comwrote:
On 22 feb, 09:51, p.le...@ctncorp.com wrote:
On Feb 22, 9:49 am, "Johan" <joh...@gmail.comwrote:
On 21 feb, 15:28, p.le...@ctncorp.com wrote:
You cannot achieve the results identical to using
XInclude, period. You may attempt to do something
like
<xsl:variable
name="everything" select="/|document('foo')"/>
I will try that, thanks.
You're not listening, are you? You *won't* get the
results identical to using XInclude without XSLT2 or
EXSLT. (For that matter, it's not as trivial as you
seem to think it should be with XSLT2 or EXSLT.) Modern
browsers do not support XSLT2 or EXSLT. If you use the
union, you'll have to check and probably rewrite all of
your XPath expressions referring to the children of
library elements anyway.
The union (as far as I know it from school) doesn't
change it inputs, it only merges to sets.
Precisely. That's the reason it won't emulate the XInclude
functionality.
If you are in a good mood
As a matter of fact, I'm not.
you might want to give me some hints about this :)
What's the point?
There's no easy way. You'll have to do that. So don't
turn it into a maintenance nightmare for the guy who
will have to work with your code after you just for the
sake of using 'union'. Do it the right way. Refer
directly to the external document.

Sorry, but I don't understand what you are trying to say.
Well, there's no royal path to geometry, as Euclid said to
Ptolemy. Perhaps you should start with the basics.
How can I refer directly to the external document
(without creating templates that match the library
elements, I already explained that's not what I want).
Read my previous posts in the thread.
I think you only explained "how to write XPath
expressions accessing other documents" for use with
apply-templates.
I explained how to write XPath expressions computing to
nodesets consisting of nodes in external documents. It
doesn't matter whether you use such expressions in select
attribute of apply-templates element, or value-of element,
or variable element. For that matter, I already explained
that in one of my previous posts, too.
How can I use it to grap/populate variables? Could you
give an example?
<xsl:variable name="$external-nodeset"
select=
"
document('external.xml')//nodes[content='something']
"/>
And what about the solution with external entities? See
"C.27 How do I include one XML file in another?" in the
XML FAQ:http://xml.silmaril.ie/authors/includes/
Google 'firefox external entity'. Summary: browsers don't
grok that. Browsers typically don't use validating parsers
and so couldn't care less for DTDs or schemata.
Can this be done with an XML schema in the same way?
No, and if it would've been possible, it wouldn't matter
anyway, because browsers typically don't use validating
parsers and therefore couldn't care less for DTDs or
schemata.
That would be a really easy solution, right?
Right. Only it doesn't work, as easy solutions tend to.

--
Pavel Lepin

Feb 22 '07 #16
On Feb 21, 10:45 am, "Johan" <joh...@gmail.comwrote:
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.
I don't think it depends on DTD's. Maybe this doesn't solve your
problem, but you can do:

$ cat foo.xml
<!DOCTYPE doc [
<!ENTITY part1 SYSTEM "foo1.xml"
]>

<doc>
<a>
hej
&part1;
</a>
</doc>
$ cat foo1.xml
<e>
hopp
</e>
$ xmllint --noent foo.xml
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ENTITY part1 SYSTEM "foo1.xml">
]>
<doc>
<a>
hej
<e>
hopp
</e>

</a>
</doc>

Feb 23 '07 #17
On Feb 23, 7:52 pm, "Arndt Jonasson"
<arndt.jonas...@gmail.comwrote:
On Feb 21, 10:45 am, "Johan" <joh...@gmail.comwrote:
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.

I don't think it depends on DTD's. Maybe this doesn't
solve your problem, but you can do:
It certainly doesn't. Firefox does not parse external
entities.
$ cat foo.xml
<!DOCTYPE doc [
<!ENTITY part1 SYSTEM "foo1.xml"
]>
Hmmm... is that another case of google groups arbitrarily
discarding information it is considering discardable for
some mysterious reason of its own? I start thinking google
is past being just bad, it is now actively evil. Probably
has something to do with Parkinson's law.

--
roy axenov

Feb 23 '07 #18
On Feb 23, 8:30 pm, "roy axenov" <r_axe...@mail.ruwrote:
On Feb 23, 7:52 pm, "Arndt Jonasson"
$ cat foo.xml
<!DOCTYPE doc [
<!ENTITY part1 SYSTEM "foo1.xml"
]>

Hmmm... is that another case of google groups arbitrarily
discarding information it is considering discardable for
some mysterious reason of its own?
Are these four lines of mine the only ones you saw of foo.xml? When I
look at my own article, I see a lot more.

Feb 26 '07 #19
On Feb 26, 11:55 am, "Arndt Jonasson"
<arndt.jonas...@gmail.comwrote:
On Feb 23, 8:30 pm, "roy axenov" <r_axe...@mail.ru>
wrote:
On Feb 23, 7:52 pm, "Arndt Jonasson"
$ cat foo.xml
<!DOCTYPE doc [
<!ENTITY part1 SYSTEM "foo1.xml"
]>
Hmmm... is that another case of google groups
arbitrarily discarding information it is considering
discardable for some mysterious reason of its own?

Are these four lines of mine the only ones you saw of
foo.xml? When I look at my own article, I see a lot more.
Nope, I saw it all. I was talking about the fact that the
trailing angle bracket on the second line is missing. I've
noticed before that GG seems to have a strange dislike for
greater-than signs, but I'm not certain what was the
problem in this case.

--
roy axenov

Feb 26 '07 #20
On Feb 26, 7:39 pm, "roy axenov" <r_axe...@mail.ruwrote:
On Feb 26, 11:55 am, "Arndt Jonasson"

<arndt.jonas...@gmail.comwrote:
On Feb 23, 8:30 pm, "roy axenov" <r_axe...@mail.ru>
wrote:
On Feb 23, 7:52 pm, "Arndt Jonasson"
$ cat foo.xml
<!DOCTYPE doc [
<!ENTITY part1 SYSTEM "foo1.xml"
]>
Hmmm... is that another case of google groups
arbitrarily discarding information it is considering
discardable for some mysterious reason of its own?
Are these four lines of mine the only ones you saw of
foo.xml? When I look at my own article, I see a lot more.

Nope, I saw it all. I was talking about the fact that the
trailing angle bracket on the second line is missing. I've
noticed before that GG seems to have a strange dislike for
greater-than signs, but I'm not certain what was the
problem in this case.
It's not impossible that I managed to delete it while pasting together
my article.

Feb 27 '07 #21

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

Similar topics

5
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;...
5
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...
3
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 = ...
8
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...
4
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...
4
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)....
11
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)...
38
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 ...
2
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...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.