sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Keith Chadwick's Avatar

Odd behavior on xsl:include / xsl:import - Figure this one out?


Question posted by: Keith Chadwick (Guest) on November 12th, 2005 02:08 AM
I have been running some tests with regards to xsl:include and xsl:import
with the same results on both and I am wondering if someone can explain this
behavior to me!

First off the xslt file is being loaded as in

dim myXSLT as new XslTransform()
myXSLT.load("scripts/clnt.home.body.xslt")

The load craps out when I change the xsl:include, tried all of the following
is xsl:import as well. The file contains a href to a file called
clnt.cmn.xslt. It contains some standard templates with names that render
particular html that is common to the site. The file is stored in a physical
directory, C:\allianceShared\xslt\clnt.cmn.xslt.

The directory allianceShared is a virtual directory in the web site called
shared and resides at the root. The transform file I am loading is off the
root within a directory called scripts. Here is the structure laid out

c:\allianceShared
xslt\
clnt.cmn.xslt

c:\AllianceNet (Website root, domain name
http://allianceNet)
shared\ (Virtual directory pointing at
c:\allianceShared)
scripts\
clnt.home.body.xslt (transformation file being loaded)
home.aspx (file making the call )

Now here is the strange thing on loading the clnt.home.body.xslt file from
within home.aspx

example 1 : works
<xsl:import href="c:\allianceShared\xslt\clnt.cmn.xslt"/> - works

example 2: works, surprise!
<xsl:import href="http://allianceNet/shared/xslt/clnt.cmn.xslt"/>

example 3: fails
<xsl:import href="../shared/xslt/clnt.cmn.xslt"/>
Now thinking that '..' usually means something else in the xslt world I
created the same virtual directory 'shared' under the scripts directory,
hence the next example/

example 4: fails
<xsl:import href="shared/xslt/clnt.cmn.xslt"/>

Now what is interesting is, example 1 works even though you are supposed to
be supplying an href? If example 2 works, meaning that it does recognize the
virtual directory 'shared' why would example 3 or 4 fail?

Of note I have other xslt files that have xsl:import statements with the
href="../somefile.xslt" and they work, but only if they are dealing with
physical directories in the web site not virtual ones.

Any thought on this?

Looking forward to seeing if Oleg can explain this one :-)

Cheers
Keith


2 Answers Posted
Oleg Tkachenko's Avatar
Guest - n/a Posts
#2: Re: Odd behavior on xsl:include / xsl:import - Figure this one out?

Keith Chadwick wrote:
[color=blue]
> Now here is the strange thing on loading the clnt.home.body.xslt file from
> within home.aspx
>
> example 1 : works
> <xsl:import href="c:\allianceShared\xslt\clnt.cmn.xslt"/> - works
>
> example 2: works, surprise!
> <xsl:import href="http://allianceNet/shared/xslt/clnt.cmn.xslt"/>
>
> example 3: fails
> <xsl:import href="../shared/xslt/clnt.cmn.xslt"/>
> Now thinking that '..' usually means something else in the xslt world I
> created the same virtual directory 'shared' under the scripts directory,
> hence the next example/
>
> example 4: fails
> <xsl:import href="shared/xslt/clnt.cmn.xslt"/>
>
> Now what is interesting is, example 1 works even though you are supposed to
> be supplying an href? If example 2 works, meaning that it does recognize the
> virtual directory 'shared' why would example 3 or 4 fail?
>
> Of note I have other xslt files that have xsl:import statements with the
> href="../somefile.xslt" and they work, but only if they are dealing with
> physical directories in the web site not virtual ones.
>
> Any thought on this?[/color]

Well, actually relative URI references in xsl:import instruction (ones
who don't work for you) are resolved relatively to base URI of the
xsl:import element node itself (hence base URI of the master stylesheet
clnt.home.body.xslt in your case).
So if both stylesheets are in the same dir, try
<xsl:import href="clnt.cmn.xslt"/>

Another issue - make sure you are loading clnt.home.body.xslt stylesheet
preserving its base URI (e.g. not from string or stream), otherwise
obviously XSLT processor won't be able to resolve relative URI references.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Keith Chadwick's Avatar
Guest - n/a Posts
#3: Re: Odd behavior on xsl:include / xsl:import - Figure this one out?

Thanks Oleg you twigged my brain regarding the load of the file. I was
using server.mappath("url") instead of a fully qualified URI. Everything
works fine now.

Cheers
Keith



"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:Oq3yKc$sDHA.4056@TK2MSFTNGP11.phx.gbl...[color=blue]
> Keith Chadwick wrote:
>[color=green]
> > Now here is the strange thing on loading the clnt.home.body.xslt file[/color][/color]
from[color=blue][color=green]
> > within home.aspx
> >
> > example 1 : works
> > <xsl:import href="c:\allianceShared\xslt\clnt.cmn.xslt"/> - works
> >
> > example 2: works, surprise!
> > <xsl:import href="http://allianceNet/shared/xslt/clnt.cmn.xslt"/>
> >
> > example 3: fails
> > <xsl:import href="../shared/xslt/clnt.cmn.xslt"/>
> > Now thinking that '..' usually means something else in the xslt world I
> > created the same virtual directory 'shared' under the scripts directory,
> > hence the next example/
> >
> > example 4: fails
> > <xsl:import href="shared/xslt/clnt.cmn.xslt"/>
> >
> > Now what is interesting is, example 1 works even though you are supposed[/color][/color]
to[color=blue][color=green]
> > be supplying an href? If example 2 works, meaning that it does recognize[/color][/color]
the[color=blue][color=green]
> > virtual directory 'shared' why would example 3 or 4 fail?
> >
> > Of note I have other xslt files that have xsl:import statements with the
> > href="../somefile.xslt" and they work, but only if they are dealing with
> > physical directories in the web site not virtual ones.
> >
> > Any thought on this?[/color]
>
> Well, actually relative URI references in xsl:import instruction (ones
> who don't work for you) are resolved relatively to base URI of the
> xsl:import element node itself (hence base URI of the master stylesheet
> clnt.home.body.xslt in your case).
> So if both stylesheets are in the same dir, try
> <xsl:import href="clnt.cmn.xslt"/>
>
> Another issue - make sure you are loading clnt.home.body.xslt stylesheet
> preserving its base URI (e.g. not from string or stream), otherwise
> obviously XSLT processor won't be able to resolve relative URI references.
> --
> Oleg Tkachenko
> XML Insider
> http://www.tkachenko.com/blog
>[/color]


 
Not the answer you were looking for? Post your question . . .
196,863 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,863 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors