XmlUrlResolver xsl:include

Discussion in 'ASP .Net' started by Gideon de Swardt, Feb 27, 2004.

  1. I am trying to do a server side transformation using an xsl:include in my
    xslt stylesheet. The include stylesheet is stored /Library/abo.Library.xslt
    and is included in multiple xslts, one example would be
    /Valuation/ValuationSelect.xslt which is also used on the client side via
    JavaScript and MSXML2.FreeThreadedDOMDocument.4.0. Client side the include
    and transformation without any problems but it is when I am trying to do the
    transformation on the server that I do get a XsltCompileException and
    IOException error "the network path was not found". Worth mentioning also is
    that the Library is a virtual folder in IIS, although I would have thought
    that the XmlUrlResolver would resolve this problem for me it does not look
    like it.

    Here is the header of my xslt


    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:include href="/Library/abo.Library.xslt"/>
    .....
    </xsl:stylesheet>

    and my C# code snippet for the transformation

    XslTransform transform = new XslTransform();
    XmlUrlResolver resolver = new XmlUrlResolver();
    resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
    transform.Load(Server.MapPath("/Organization/OrganizationSearch.xslt"),
    resolver);


    Any ideas will be much appreciated

    Gideon de Swardt
     
    Gideon de Swardt, Feb 27, 2004
    #1
    1. Advertising

  2. Hi, Gideon de Swardt,

    The problem is that your includes are web-relative *and* dependent on the
    root of the web-application, but the XmlUrlResolver tries to resolve them
    relatively to the filesystem, because you pass the first parameter of the
    Load method as a file:\\. You should either pass the absolute url of the
    document (http://) or you should change the includes to be relative to the
    document and independent of the web-application structure (using ../ instead
    of /).

    Hope this helps
    Martin

    "Gideon de Swardt" <> wrote in message
    news:ub9908U$...
    > I am trying to do a server side transformation using an xsl:include in my
    > xslt stylesheet. The include stylesheet is stored

    /Library/abo.Library.xslt
    > and is included in multiple xslts, one example would be
    > /Valuation/ValuationSelect.xslt which is also used on the client side via
    > JavaScript and MSXML2.FreeThreadedDOMDocument.4.0. Client side the include
    > and transformation without any problems but it is when I am trying to do

    the
    > transformation on the server that I do get a XsltCompileException and
    > IOException error "the network path was not found". Worth mentioning also

    is
    > that the Library is a virtual folder in IIS, although I would have thought
    > that the XmlUrlResolver would resolve this problem for me it does not look
    > like it.
    >
    > Here is the header of my xslt
    >
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:include href="/Library/abo.Library.xslt"/>
    > .....
    > </xsl:stylesheet>
    >
    > and my C# code snippet for the transformation
    >
    > XslTransform transform = new XslTransform();
    > XmlUrlResolver resolver = new XmlUrlResolver();
    > resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
    > transform.Load(Server.MapPath("/Organization/OrganizationSearch.xslt"),
    > resolver);
    >
    >
    > Any ideas will be much appreciated
    >
    > Gideon de Swardt
    >
    >
     
    Martin Dechev, Feb 27, 2004
    #2
    1. Advertising

  3. Hi Martin

    Thanks for your response

    but

    dont want to specify the url cause same solution might be installed on
    different servers using different versions of this file.

    tried relative path but because my Library folder is virtual directory in
    IIS and the physical location on the file system is outside the root of the
    website i returns the wrong path and returns an IOException example

    webroot folder is c:\inetpub\wwwroot\webapp
    where as the library folder is c:\common\library

    so the url resolver will try and return
    c:\inetpub\wwwroot\webapp\Library\abo.Library.xslt instead of
    c:\common\library\abo.library.xslt. I would have thought that the Resolver
    would be able to resolve urls across virtual folders. The reason for the
    virtual folder is that multiple websites use the same folder and all have a
    virtual folder pointing to the c:\common\library folder.

    and the last thing i want to do is hard code the location of this file in
    the xslt using file:// cause then i would not be able to use the xslt on the
    client side.


    so the question is what to do

    Regards

    G


    "Martin Dechev" <> wrote in message
    news:%236BChLV$...
    > Hi, Gideon de Swardt,
    >
    > The problem is that your includes are web-relative *and* dependent on the
    > root of the web-application, but the XmlUrlResolver tries to resolve them
    > relatively to the filesystem, because you pass the first parameter of the
    > Load method as a file:\\. You should either pass the absolute url of the
    > document (http://) or you should change the includes to be relative to the
    > document and independent of the web-application structure (using ../

    instead
    > of /).
    >
    > Hope this helps
    > Martin
    >
    > "Gideon de Swardt" <> wrote in message
    > news:ub9908U$...
    > > I am trying to do a server side transformation using an xsl:include in

    my
    > > xslt stylesheet. The include stylesheet is stored

    > /Library/abo.Library.xslt
    > > and is included in multiple xslts, one example would be
    > > /Valuation/ValuationSelect.xslt which is also used on the client side

    via
    > > JavaScript and MSXML2.FreeThreadedDOMDocument.4.0. Client side the

    include
    > > and transformation without any problems but it is when I am trying to do

    > the
    > > transformation on the server that I do get a XsltCompileException and
    > > IOException error "the network path was not found". Worth mentioning

    also
    > is
    > > that the Library is a virtual folder in IIS, although I would have

    thought
    > > that the XmlUrlResolver would resolve this problem for me it does not

    look
    > > like it.
    > >
    > > Here is the header of my xslt
    > >
    > >
    > > <?xml version="1.0" encoding="utf-8"?>
    > > <xsl:stylesheet version="1.0"
    > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > > <xsl:include href="/Library/abo.Library.xslt"/>
    > > .....
    > > </xsl:stylesheet>
    > >
    > > and my C# code snippet for the transformation
    > >
    > > XslTransform transform = new XslTransform();
    > > XmlUrlResolver resolver = new XmlUrlResolver();
    > > resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
    > > transform.Load(Server.MapPath("/Organization/OrganizationSearch.xslt"),
    > > resolver);
    > >
    > >
    > > Any ideas will be much appreciated
    > >
    > > Gideon de Swardt
    > >
    > >

    >
    >
     
    Gideon de Swardt, Feb 27, 2004
    #3
  4. Hi, Gideon de Swardt,

    You should use something like:

    transform.Load("http://domain.com/site/Organization/OrganizationSearch.xslt"
    , resolver);

    or

    transform.Load("http://some IP
    Address/site/Organization/OrganizationSearch.xslt", resolver);

    for the website-root-relative paths to be resolved.

    You can store the the first part of the url in a config file and change it
    for each solution. i.e.:

    transform.Load(
    System.Configuration.ConfigurationSettings.AppSettings["RootUrl"] +
    "/Organization/OrganizationSearch.xslt", resolver);

    and in the web.config or the app.config:

    <configuration>
    <appSettings>
    <add key="RootUrl" value="http://domain.com/site" />
    </appSettings>
    </configuration>

    Greetings
    Martin
    "Gideon de Swardt" <> wrote in message
    news:es6iXcV$...
    > Hi Martin
    >
    > Thanks for your response
    >
    > but
    >
    > dont want to specify the url cause same solution might be installed on
    > different servers using different versions of this file.
    >
    > tried relative path but because my Library folder is virtual directory in
    > IIS and the physical location on the file system is outside the root of

    the
    > website i returns the wrong path and returns an IOException example
    >
    > webroot folder is c:\inetpub\wwwroot\webapp
    > where as the library folder is c:\common\library
    >
    > so the url resolver will try and return
    > c:\inetpub\wwwroot\webapp\Library\abo.Library.xslt instead of
    > c:\common\library\abo.library.xslt. I would have thought that the Resolver
    > would be able to resolve urls across virtual folders. The reason for the
    > virtual folder is that multiple websites use the same folder and all have

    a
    > virtual folder pointing to the c:\common\library folder.
    >
    > and the last thing i want to do is hard code the location of this file in
    > the xslt using file:// cause then i would not be able to use the xslt on

    the
    > client side.
    >
    >
    > so the question is what to do
    >
    > Regards
    >
    > G
    >
    >
    > "Martin Dechev" <> wrote in message
    > news:%236BChLV$...
    > > Hi, Gideon de Swardt,
    > >
    > > The problem is that your includes are web-relative *and* dependent on

    the
    > > root of the web-application, but the XmlUrlResolver tries to resolve

    them
    > > relatively to the filesystem, because you pass the first parameter of

    the
    > > Load method as a file:\\. You should either pass the absolute url of the
    > > document (http://) or you should change the includes to be relative to

    the
    > > document and independent of the web-application structure (using ../

    > instead
    > > of /).
    > >
    > > Hope this helps
    > > Martin
    > >
    > > "Gideon de Swardt" <> wrote in message
    > > news:ub9908U$...
    > > > I am trying to do a server side transformation using an xsl:include in

    > my
    > > > xslt stylesheet. The include stylesheet is stored

    > > /Library/abo.Library.xslt
    > > > and is included in multiple xslts, one example would be
    > > > /Valuation/ValuationSelect.xslt which is also used on the client side

    > via
    > > > JavaScript and MSXML2.FreeThreadedDOMDocument.4.0. Client side the

    > include
    > > > and transformation without any problems but it is when I am trying to

    do
    > > the
    > > > transformation on the server that I do get a XsltCompileException and
    > > > IOException error "the network path was not found". Worth mentioning

    > also
    > > is
    > > > that the Library is a virtual folder in IIS, although I would have

    > thought
    > > > that the XmlUrlResolver would resolve this problem for me it does not

    > look
    > > > like it.
    > > >
    > > > Here is the header of my xslt
    > > >
    > > >
    > > > <?xml version="1.0" encoding="utf-8"?>
    > > > <xsl:stylesheet version="1.0"
    > > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > > > <xsl:include href="/Library/abo.Library.xslt"/>
    > > > .....
    > > > </xsl:stylesheet>
    > > >
    > > > and my C# code snippet for the transformation
    > > >
    > > > XslTransform transform = new XslTransform();
    > > > XmlUrlResolver resolver = new XmlUrlResolver();
    > > > resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
    > > >

    transform.Load(Server.MapPath("/Organization/OrganizationSearch.xslt"),
    > > > resolver);
    > > >
    > > >
    > > > Any ideas will be much appreciated
    > > >
    > > > Gideon de Swardt
    > > >
    > > >

    > >
    > >

    >
    >
     
    Martin Dechev, Feb 27, 2004
    #4
  5. Thanks Martin

    I changed my code to point to the abs url
    http://localhost/Valuation/ValuationSelect.xslt and that works if i use the
    XslTransform object, but if I use System.Web.UI.WebControls.Xml to do the
    transformation I can not pass the full url as the TransformSource, i receive
    the following error.

    Invalid path for MapPath
    '/Valuation/http://localhost/Valuation/ValuationSelect.xslt'. A virtual path
    is expected.

    Is there any way to indicate to the Xml Control not to use virtual paths but
    absolute paths, without writing my own control to do the transformation for
    me?

    Regards

    Gideon
     
    Gideon de Swardt, Mar 1, 2004
    #5
  6. Hi, Gideon,

    Could you please post the code that illustrates the problem. Is there a
    particular reason to use the TransformSource property instead of assigning
    an instance of XslTransform class to the property Transform? Like it is done
    in the example for the Xml class topic:

    http://msdn.microsoft.com/library/e...temwebuiwebcontrolsxmlclasstransformtopic.asp

    Greetings
    Martin
    "Gideon de Swardt" <> wrote in message
    news:eCvcAM4$...
    > Thanks Martin
    >
    > I changed my code to point to the abs url
    > http://localhost/Valuation/ValuationSelect.xslt and that works if i use

    the
    > XslTransform object, but if I use System.Web.UI.WebControls.Xml to do the
    > transformation I can not pass the full url as the TransformSource, i

    receive
    > the following error.
    >
    > Invalid path for MapPath
    > '/Valuation/http://localhost/Valuation/ValuationSelect.xslt'. A virtual

    path
    > is expected.
    >
    > Is there any way to indicate to the Xml Control not to use virtual paths

    but
    > absolute paths, without writing my own control to do the transformation

    for
    > me?
    >
    > Regards
    >
    > Gideon
    >
    >
     
    Martin Dechev, Mar 1, 2004
    #6
  7. The TransformSource property is set in the aspx page rather than in the
    compiled C# code, which allows for customization between multiple websites
    without changing source code and having to re-compile the binaries.

    My work around for this was to create a custom web control as bellow, which
    also allowed me to set my default ArgumentLists as well, while loading the
    base.Transform Xslt with the full url and XmlUrlResolver.

    public class Xml : System.Web.UI.WebControls.Xml
    {
    public System.Xml.XmlUrlResolver UrlResolver;
    protected override void Render(HtmlTextWriter writer)
    {
    Company.Web.Page thePage = (Company.Web.Page) this.Page;
    //TransformArgumentList
    this.TransformArgumentList = new XsltArgumentList();

    this.TransformArgumentList.AddExtensionObject("http://www.company.net/XslLib
    rary", new Company.Library());
    //XmlUrlResolver
    if (this.UrlResolver == null)
    {
    this.UrlResolver = new XmlUrlResolver();
    this.UrlResolver.Credentials =
    System.Net.CredentialCache.DefaultCredentials;
    }
    //Load Transform Source
    if (this.TransformSource.Length > 0)
    {
    string transformSource = thePage.UrlBase +
    thePage.ResolveUrl(this.TransformSource); //thePage.UrlBase returns the base
    url eg. http://localhost
    this.TransformSource = null;
    base.Transform = new XslTransform();
    base.Transform.Load(transformSource, this.UrlResolver);
    }
    //Render
    base.Render(writer);
    }
    }


    Thanks for all your help

    Regards

    Gideon de Sward
     
    Gideon de Swardt, Mar 1, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klaus Friese
    Replies:
    0
    Views:
    468
    Klaus Friese
    Nov 22, 2004
  2. Replies:
    1
    Views:
    3,611
    A. Bolmarcich
    May 27, 2005
  3. lele1979

    xsl:Include e xsl:call-template

    lele1979, Nov 6, 2006, in forum: XML
    Replies:
    1
    Views:
    562
  4. Colin Bowern
    Replies:
    0
    Views:
    304
    Colin Bowern
    Jan 2, 2004
  5. David Thielen

    XmlUrlResolver not working right

    David Thielen, Dec 22, 2006, in forum: ASP .Net Security
    Replies:
    2
    Views:
    190
    David Thielen
    Dec 30, 2006
Loading...

Share This Page