XSL Error with document() function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rox.scott

    XSL Error with document() function

    Can someone please explain why this happens?
    The expected output is 3, but uncommenting line 7 makes the output 0.
    Why ???

    VB.NET code: ** note the commented line, this is the culprit **
    Dim xsl As New System.Xml.Xsl. XslTransform()
    Dim xw As New System.IO.Strin gWriter()
    Dim xmldoc As New System.Xml.XmlD ocument()
    Dim xsldoc As New System.Xml.XmlD ocument()
    xmldoc.Load("te st.xml")
    xsldoc.Load("te st.xsl")
    'xsldoc.LoadXml (xsldoc.OuterXm l)
    xsl.Load(xsldoc .CreateNavigato r)
    xsl.Transform(x mldoc.CreateNav igator, Nothing, xw)
    Console.Write(x w.ToString)
    XML input: (test.xml)
    <xml>
    <node1 val="hello world" />
    </xml>

    XSL input: (test.xsl)
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <xsl:value-of select="count(d ocument('')//*)" />
    </xsl:template>
    </xsl:stylesheet>

    Please explain why this happens, I do not want to use any file I/O in my
    program!
    Thanks.

    --scott
  • Nigel Armstrong

    #2
    RE: XSL Error with document() function

    Hi

    What are you trying to achieve here - is it the count of elements inside the
    source document, or the stylesheet? From the MSXML reference:

    If an empty string is passed to the document() function, the result is the
    source XML of the XSLT document itself, unless the second argument is given
    (and is not null). In the latter case, the URL of the document is the base
    URL of the node contained in the second element.

    So if you use an empty string for the document function, then the context is
    actually the stylesheet, not the source document.

    So leave the document('') function out!

    HTH

    Nigel

    "rox.scott" wrote:
    [color=blue]
    > Can someone please explain why this happens?
    > The expected output is 3, but uncommenting line 7 makes the output 0.
    > Why ???
    >
    > VB.NET code: ** note the commented line, this is the culprit **
    > Dim xsl As New System.Xml.Xsl. XslTransform()
    > Dim xw As New System.IO.Strin gWriter()
    > Dim xmldoc As New System.Xml.XmlD ocument()
    > Dim xsldoc As New System.Xml.XmlD ocument()
    > xmldoc.Load("te st.xml")
    > xsldoc.Load("te st.xsl")
    > 'xsldoc.LoadXml (xsldoc.OuterXm l)
    > xsl.Load(xsldoc .CreateNavigato r)
    > xsl.Transform(x mldoc.CreateNav igator, Nothing, xw)
    > Console.Write(x w.ToString)
    > XML input: (test.xml)
    > <xml>
    > <node1 val="hello world" />
    > </xml>
    >
    > XSL input: (test.xsl)
    > <xsl:styleshe et version="1.0"
    > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    > <xsl:template match="/">
    > <xsl:value-of select="count(d ocument('')//*)" />
    > </xsl:template>
    > </xsl:stylesheet>
    >
    > Please explain why this happens, I do not want to use any file I/O in my
    > program!
    > Thanks.
    >
    > --scott[/color]

    Comment

    • rox.scott

      #3
      RE: XSL Error with document() function

      Yes, I want count of the stylesheet nodes.
      This is a simplification of my real-world case, I don't actually want a node
      count, but illustrates the problem.

      In either case, I should not get 0 as a result.

      --scott

      "Nigel Armstrong" wrote:
      [color=blue]
      > Hi
      >
      > What are you trying to achieve here - is it the count of elements inside the
      > source document, or the stylesheet? From the MSXML reference:
      >
      > If an empty string is passed to the document() function, the result is the
      > source XML of the XSLT document itself, unless the second argument is given
      > (and is not null). In the latter case, the URL of the document is the base
      > URL of the node contained in the second element.
      >
      > So if you use an empty string for the document function, then the context is
      > actually the stylesheet, not the source document.
      >
      > So leave the document('') function out!
      >
      > HTH
      >
      > Nigel
      >
      > "rox.scott" wrote:
      >[color=green]
      > > Can someone please explain why this happens?
      > > The expected output is 3, but uncommenting line 7 makes the output 0.
      > > Why ???
      > >
      > > VB.NET code: ** note the commented line, this is the culprit **
      > > Dim xsl As New System.Xml.Xsl. XslTransform()
      > > Dim xw As New System.IO.Strin gWriter()
      > > Dim xmldoc As New System.Xml.XmlD ocument()
      > > Dim xsldoc As New System.Xml.XmlD ocument()
      > > xmldoc.Load("te st.xml")
      > > xsldoc.Load("te st.xsl")
      > > 'xsldoc.LoadXml (xsldoc.OuterXm l)
      > > xsl.Load(xsldoc .CreateNavigato r)
      > > xsl.Transform(x mldoc.CreateNav igator, Nothing, xw)
      > > Console.Write(x w.ToString)
      > > XML input: (test.xml)
      > > <xml>
      > > <node1 val="hello world" />
      > > </xml>
      > >
      > > XSL input: (test.xsl)
      > > <xsl:styleshe et version="1.0"
      > > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
      > > <xsl:template match="/">
      > > <xsl:value-of select="count(d ocument('')//*)" />
      > > </xsl:template>
      > > </xsl:stylesheet>
      > >
      > > Please explain why this happens, I do not want to use any file I/O in my
      > > program!
      > > Thanks.
      > >
      > > --scott[/color][/color]

      Comment

      • Oleg Tkachenko [MVP]

        #4
        Re: XSL Error with document() function

        rox.scott wrote:
        [color=blue]
        > Can someone please explain why this happens?
        > The expected output is 3, but uncommenting line 7 makes the output 0.[/color]

        When you load XSLT from a string, it has no base URI and relatiev URIs
        cannot be resolved therefore.
        Don't load XSLT from a string or if you do need, provide base URI:
        xslt.Load(new XmlTextReader(" foo.xsl", new StringReader(st rXSL)));

        --
        Oleg Tkachenko [XML MVP]

        Comment

        • Oleg Tkachenko [MVP]

          #5
          Re: XSL Error with document() function

          Nigel Armstrong wrote:
          [color=blue]
          > So if you use an empty string for the document function, then the context is
          > actually the stylesheet, not the source document.
          >
          > So leave the document('') function out![/color]

          In fact document('') is quite useful technique, which enables XSLT
          introspection - a stylesheet can process itself. E.g. this is commonly
          used for embedding loopup tables within a stylesheet.

          --
          Oleg Tkachenko [XML MVP]

          Comment

          • rox.scott

            #6
            Re: XSL Error with document() function

            It is strange, this all works just fine using MSXML4 objects instead of XML.NET
            I guess between the implementation of MSXML4 and XML.NET they forgot the
            purpose of the special case document('').

            Obviously if I were capable of resolving a URI then I would just use
            document(URI) instead of empty string. I imagine the original programmers
            thought of this case and that is why the document('') was originally offered.
            I am not sure of its value anymore. When I provide a base URI as in Oleg's
            code above, the content of the XSL in memory is ignored and the resolved URI
            is used instead.

            W3C spec or not, it is too bad that XML.NET is intrinsically tied to the
            file system. My program has access neither to write nor read from the file
            system. I guess I will use MSXML4.

            Thank you.


            "Oleg Tkachenko [MVP]" wrote:
            [color=blue]
            > rox.scott wrote:
            >[color=green]
            > > Can someone please explain why this happens?
            > > The expected output is 3, but uncommenting line 7 makes the output 0.[/color]
            >
            > When you load XSLT from a string, it has no base URI and relatiev URIs
            > cannot be resolved therefore.
            > Don't load XSLT from a string or if you do need, provide base URI:
            > xslt.Load(new XmlTextReader(" foo.xsl", new StringReader(st rXSL)));
            >
            > --
            > Oleg Tkachenko [XML MVP]
            > http://blog.tkachenko.com
            >[/color]

            Comment

            • Nigel Armstrong

              #7
              Re: XSL Error with document() function

              Hi Rox

              I think this may be classed as a bug - I've done some limited testing using
              the System.Xml.Quer y.XsltCommand in .NET 2.0 as well...there is an improvment
              from .NET 1.0/1.1, in that the Exception messages are more clear, but I don't
              think that the issue is fixed.

              I know you can't have File IO, but as an alternative, could you return your
              stylesheets from a URL using ASP.NET to hook into your (I guess) database
              storage.

              Nigel

              "rox.scott" wrote:
              [color=blue]
              > It is strange, this all works just fine using MSXML4 objects instead of XML.NET
              > I guess between the implementation of MSXML4 and XML.NET they forgot the
              > purpose of the special case document('').
              >
              > Obviously if I were capable of resolving a URI then I would just use
              > document(URI) instead of empty string. I imagine the original programmers
              > thought of this case and that is why the document('') was originally offered.
              > I am not sure of its value anymore. When I provide a base URI as in Oleg's
              > code above, the content of the XSL in memory is ignored and the resolved URI
              > is used instead.
              >
              > W3C spec or not, it is too bad that XML.NET is intrinsically tied to the
              > file system. My program has access neither to write nor read from the file
              > system. I guess I will use MSXML4.
              >
              > Thank you.
              >
              >
              > "Oleg Tkachenko [MVP]" wrote:
              >[color=green]
              > > rox.scott wrote:
              > >[color=darkred]
              > > > Can someone please explain why this happens?
              > > > The expected output is 3, but uncommenting line 7 makes the output 0.[/color]
              > >
              > > When you load XSLT from a string, it has no base URI and relatiev URIs
              > > cannot be resolved therefore.
              > > Don't load XSLT from a string or if you do need, provide base URI:
              > > xslt.Load(new XmlTextReader(" foo.xsl", new StringReader(st rXSL)));
              > >
              > > --
              > > Oleg Tkachenko [XML MVP]
              > > http://blog.tkachenko.com
              > >[/color][/color]

              Comment

              • Oleg Tkachenko [MVP]

                #8
                Re: XSL Error with document() function

                rox.scott wrote:
                [color=blue]
                > It is strange, this all works just fine using MSXML4 objects instead of XML.NET[/color]

                It works fine in .NET if you provide base URI for your stylesheet.
                [color=blue]
                > I guess between the implementation of MSXML4 and XML.NET they forgot the
                > purpose of the special case document('').[/color]

                There is nothing special about document('') - it's just zero-length
                realtive URI to be resolved.
                [color=blue]
                > Obviously if I were capable of resolving a URI then I would just use
                > document(URI) instead of empty string. I imagine the original programmers
                > thought of this case and that is why the document('') was originally offered.
                > I am not sure of its value anymore. When I provide a base URI as in Oleg's
                > code above, the content of the XSL in memory is ignored and the resolved URI
                > is used instead.[/color]

                You seems to be working with MSXML too much. There is no such thing as
                XSL in memory. In .NET as well as in many other XSLT implementations
                XSLT is being compiled to binary representation prior to transformation
                and this binary compiled stylesheet of course doesn't contain source
                document.
                [color=blue]
                > W3C spec or not, it is too bad that XML.NET is intrinsically tied to the
                > file system.[/color]

                It doesn't.
                [color=blue]
                > My program has access neither to write nor read from the file
                > system. I guess I will use MSXML4.[/color]
                You can easily workaround this problem in .NET having source of the XSLT
                stylesheet stored in some form (string or XPathDocument) and providing
                custom XmlResolver, which resolves "" to that document (return it as
                Stream or XPathNavigator in GetEntity() method).

                --
                Oleg Tkachenko [XML MVP]

                Comment

                • Oleg Tkachenko [MVP]

                  #9
                  Re: XSL Error with document() function

                  Nigel Armstrong wrote:
                  [color=blue]
                  > I think this may be classed as a bug - I've done some limited testing using
                  > the System.Xml.Quer y.XsltCommand in .NET 2.0 as well...there is an improvment
                  > from .NET 1.0/1.1, in that the Exception messages are more clear, but I don't
                  > think that the issue is fixed.[/color]

                  I don't think that's a bug. That's by design. XSLT allows such behaviour
                  when compiled XSLT stylesheet has no source representation - e.g. when
                  you compile C++ code to exe, there is no way for exe to return you
                  source C++ code, right? So why in XSLT it's a bug?

                  --
                  Oleg Tkachenko [XML MVP]

                  Comment

                  • Nigel Armstrong

                    #10
                    Re: XSL Error with document() function

                    Hi Oleg

                    This is a fun discussion!!

                    If you read the spec:

                    Note that a zero-length URI reference is a reference to the document
                    relative to which the URI reference is being resolved; thus document("")
                    refers to the root node of the stylesheet; the tree representation of the
                    stylesheet is exactly the same as if the XML document containing the
                    stylesheet was the initial source document.

                    So if you left out document(''), and used the stylesheet itself as the
                    source document, you might expect to get the same results - without setting a
                    BaseURI, or writing a custom resolver.

                    Nigel

                    "Oleg Tkachenko [MVP]" wrote:
                    [color=blue]
                    > Nigel Armstrong wrote:
                    >[color=green]
                    > > I think this may be classed as a bug - I've done some limited testing using
                    > > the System.Xml.Quer y.XsltCommand in .NET 2.0 as well...there is an improvment
                    > > from .NET 1.0/1.1, in that the Exception messages are more clear, but I don't
                    > > think that the issue is fixed.[/color]
                    >
                    > I don't think that's a bug. That's by design. XSLT allows such behaviour
                    > when compiled XSLT stylesheet has no source representation - e.g. when
                    > you compile C++ code to exe, there is no way for exe to return you
                    > source C++ code, right? So why in XSLT it's a bug?
                    >
                    > --
                    > Oleg Tkachenko [XML MVP]
                    > http://blog.tkachenko.com
                    >[/color]

                    Comment

                    • Nigel Armstrong

                      #11
                      Re: XSL Error with document() function

                      Hi Oleg

                      I've just written some sample code supplying a base URI when loading the
                      stylesheet, and it doesn't seem to be working for me. Perhaps you could take
                      a look at it!

                      Nigel

                      test.xml
                      <?xml version="1.0"?>
                      <?xml-stylesheet type='text/xsl' href='test.xsl' ?>
                      <root><child>te xt</child></root>

                      test.xsl
                      <?xml version='1.0'?>
                      <xsl:styleshe et version='1.0'
                      xmlns:xsl='http ://www.w3.org/1999/XSL/Transform' >
                      <xsl:template match='/'>
                      <root><xsl:valu e-of select='count(d ocument(&apos;& apos;)//*)'/></root>
                      </xsl:template>
                      </xsl:stylesheet>

                      Works:
                      Dim r As New MyResolver

                      'Dim s As New Xml.XmlTextRead er("file:///C:/test.xsl", New
                      IO.FileStream(" ../test.xsl", IO.FileMode.Ope n))
                      Dim d As New Xml.XmlDocument
                      d.Load("../test.xml")

                      Dim t As New Xml.Xsl.XslTran sform
                      t.Load("../test.xsl", r)
                      't.Load(s, r, Nothing)
                      Dim sw As New IO.StringWriter

                      t.Transform(d, Nothing, sw, r)

                      MessageBox.Show (sw.ToString())


                      Doesn't work:
                      Dim r As New MyResolver

                      Dim s As New Xml.XmlTextRead er("file:///C:/test.xsl", New
                      IO.FileStream(" ../test.xsl", IO.FileMode.Ope n))
                      Dim d As New Xml.XmlDocument
                      d.Load("../test.xml")

                      Dim t As New Xml.Xsl.XslTran sform
                      't.Load("../test.xsl", r)
                      t.Load(s, r, Nothing)
                      Dim sw As New IO.StringWriter

                      t.Transform(d, Nothing, sw, r)

                      MessageBox.Show (sw.ToString())


                      Custom resolver that always returns a reference to the same stylesheet
                      Public Class MyResolver
                      Inherits Xml.XmlResolver

                      Public Overrides WriteOnly Property Credentials() As
                      System.Net.ICre dentials
                      Set(ByVal Value As System.Net.ICre dentials)

                      End Set
                      End Property

                      Public Overrides Function GetEntity(ByVal absoluteUri As System.Uri,
                      ByVal role As String, ByVal ofObjectToRetur n As System.Type) As Object
                      Return New IO.FileStream(" ..\test.xsl", IO.FileMode.Ope n)
                      End Function
                      End Class



                      "Oleg Tkachenko [MVP]" wrote:
                      [color=blue]
                      > rox.scott wrote:
                      >[color=green]
                      > > It is strange, this all works just fine using MSXML4 objects instead of XML.NET[/color]
                      >
                      > It works fine in .NET if you provide base URI for your stylesheet.
                      >[color=green]
                      > > I guess between the implementation of MSXML4 and XML.NET they forgot the
                      > > purpose of the special case document('').[/color]
                      >
                      > There is nothing special about document('') - it's just zero-length
                      > realtive URI to be resolved.
                      >[color=green]
                      > > Obviously if I were capable of resolving a URI then I would just use
                      > > document(URI) instead of empty string. I imagine the original programmers
                      > > thought of this case and that is why the document('') was originally offered.
                      > > I am not sure of its value anymore. When I provide a base URI as in Oleg's
                      > > code above, the content of the XSL in memory is ignored and the resolved URI
                      > > is used instead.[/color]
                      >
                      > You seems to be working with MSXML too much. There is no such thing as
                      > XSL in memory. In .NET as well as in many other XSLT implementations
                      > XSLT is being compiled to binary representation prior to transformation
                      > and this binary compiled stylesheet of course doesn't contain source
                      > document.
                      >[color=green]
                      > > W3C spec or not, it is too bad that XML.NET is intrinsically tied to the
                      > > file system.[/color]
                      >
                      > It doesn't.
                      >[color=green]
                      > > My program has access neither to write nor read from the file
                      > > system. I guess I will use MSXML4.[/color]
                      > You can easily workaround this problem in .NET having source of the XSLT
                      > stylesheet stored in some form (string or XPathDocument) and providing
                      > custom XmlResolver, which resolves "" to that document (return it as
                      > Stream or XPathNavigator in GetEntity() method).
                      >
                      > --
                      > Oleg Tkachenko [XML MVP]
                      > http://blog.tkachenko.com
                      >[/color]

                      Comment

                      • rox.scott

                        #12
                        Re: XSL Error with document() function

                        Here is a piece of code that replicates [using MSXML] the exact functionality
                        in the code snippet [using XML.NET] I first posted, above. The only addition
                        is the last line, which shows you that indeed the URI is null if you load
                        from string instead of from file:
                        Dim xmldoc As New MSXML2.DOMDocum entClass()
                        Dim xsldoc As New MSXML2.DOMDocum entClass()
                        xmldoc.load("te st.xml")
                        xsldoc.load("te st.xsl")
                        ' xsldoc.loadXML( xsldoc.xml)
                        Console.WriteLi ne(xmldoc.trans formNode(xsldoc ))
                        Console.WriteLi ne(xsldoc.url)

                        Note that count() returns the same result no matter if you comment out the
                        string-load line or not.

                        I would enjoy very much to stop using MSXML, but it seems I cannot since it
                        is the only platform that provides the functionality I need.

                        --scott

                        "Oleg Tkachenko [MVP]" wrote:
                        [color=blue]
                        > rox.scott wrote:
                        >[color=green]
                        > > It is strange, this all works just fine using MSXML4 objects instead of XML.NET[/color]
                        >
                        > It works fine in .NET if you provide base URI for your stylesheet.
                        >[color=green]
                        > > I guess between the implementation of MSXML4 and XML.NET they forgot the
                        > > purpose of the special case document('').[/color]
                        >
                        > There is nothing special about document('') - it's just zero-length
                        > realtive URI to be resolved.
                        >[color=green]
                        > > Obviously if I were capable of resolving a URI then I would just use
                        > > document(URI) instead of empty string. I imagine the original programmers
                        > > thought of this case and that is why the document('') was originally offered.
                        > > I am not sure of its value anymore. When I provide a base URI as in Oleg's
                        > > code above, the content of the XSL in memory is ignored and the resolved URI
                        > > is used instead.[/color]
                        >
                        > You seems to be working with MSXML too much. There is no such thing as
                        > XSL in memory. In .NET as well as in many other XSLT implementations
                        > XSLT is being compiled to binary representation prior to transformation
                        > and this binary compiled stylesheet of course doesn't contain source
                        > document.
                        >[color=green]
                        > > W3C spec or not, it is too bad that XML.NET is intrinsically tied to the
                        > > file system.[/color]
                        >
                        > It doesn't.
                        >[color=green]
                        > > My program has access neither to write nor read from the file
                        > > system. I guess I will use MSXML4.[/color]
                        > You can easily workaround this problem in .NET having source of the XSLT
                        > stylesheet stored in some form (string or XPathDocument) and providing
                        > custom XmlResolver, which resolves "" to that document (return it as
                        > Stream or XPathNavigator in GetEntity() method).
                        >
                        > --
                        > Oleg Tkachenko [XML MVP]
                        > http://blog.tkachenko.com
                        >[/color]

                        Comment

                        • Oleg Tkachenko [MVP]

                          #13
                          Re: XSL Error with document() function

                          Nigel Armstrong wrote:[color=blue]
                          > If you read the spec:
                          >
                          > Note that a zero-length URI reference is a reference to the document
                          > relative to which the URI reference is being resolved; thus document("")
                          > refers to the root node of the stylesheet; the tree representation of the
                          > stylesheet is exactly the same as if the XML document containing the
                          > stylesheet was the initial source document.
                          >
                          > So if you left out document(''), and used the stylesheet itself as the
                          > source document, you might expect to get the same results - without setting a
                          > BaseURI, or writing a custom resolver.[/color]

                          Well, that might be your interpretation of the spec, but if you read
                          again, you can see that document("") is just resolved to the root node
                          of the stylesheet, no more. The spec doesn't say that XSLT processor
                          must store XML representation of the stylesheet internally just for that
                          case, it just say what should be the result. Developers of the
                          XslTransform class decided not to expose internal stylesheet
                          representation when evaluating document(""), but to load it from the
                          source document - it's a legal choice. The same goes in Apache Xalan,
                          when you compile XSLT stylesheet to java bytecode - then which XSLT
                          source you are talking about? The same will be in .NET 2.0, where XSLT
                          is compiled to MSIL.
                          And I believe you can get the same behaviour when loading stylesheet
                          from a string in JAXP.
                          If you load XslTransform in a common way - from a file, XmlReader or
                          XPathNavigator - they all preserve base URI of the stylesheet so
                          document("") works just fine. If you provide no base URI (loading from a
                          string) - there is nothing to resolve relatively to, so it fails.
                          In this case there is a simple workaround - using custom XmlResolver,
                          it's less than dozen lines of code.

                          --
                          Oleg Tkachenko [XML MVP]

                          Comment

                          • Oleg Tkachenko [MVP]

                            #14
                            Re: XSL Error with document() function

                            Nigel Armstrong wrote:
                            [color=blue]
                            > I've just written some sample code supplying a base URI when loading the
                            > stylesheet, and it doesn't seem to be working for me. Perhaps you could take
                            > a look at it![/color]

                            Well, you better not resolve to a file on the filesystem, but return the
                            same XSLT stylesheet in memory. This way one can avoid I/O at the
                            runtime altogether (that's what original poster actually wanted):

                            Here is a simple XmlResolver:

                            public class MyResolver : XmlUrlResolver {
                            private XPathNavigator nav;

                            public MyResolver(XPat hNavigator nav) {
                            this.nav = nav;
                            }

                            public override object GetEntity(Uri absoluteUri, string role, Type
                            ofObjectToRetur n) {
                            if (absoluteUri.Sc heme == "my")
                            return nav.Clone();
                            else
                            return base.GetEntity( absoluteUri, role, ofObjectToRetur n);
                            }
                            }

                            and here is it's usage:

                            string xml = "<foo/>";
                            string xsl = @"
                            <xsl:styleshe et version=""1.0""
                            xmlns:xsl=""htt p://www.w3.org/1999/XSL/Transform"">
                            <xsl:template match=""/"">
                            <xsl:value-of select=""count( document('')//*)""/>
                            </xsl:template>
                            </xsl:stylesheet> ";

                            XPathDocument doc = new XPathDocument(n ew StringReader(xm l));
                            XslTransform xslt = new XslTransform();
                            XPathDocument xslDoc = new XPathDocument(n ew
                            XmlTextReader(" my://uri", new StringReader(xs l)));
                            xslt.Load(xslDo c);

                            //Runtime - no I/O here
                            xslt.Transform( doc, null, Console.Out, new
                            MyResolver(xslD oc.CreateNaviga tor()));

                            --
                            Oleg Tkachenko [XML MVP]

                            Comment

                            • Oleg Tkachenko [MVP]

                              #15
                              Re: XSL Error with document() function

                              rox.scott wrote:
                              [color=blue]
                              > Here is a piece of code that replicates [using MSXML] the exact functionality
                              > in the code snippet [using XML.NET] I first posted, above. The only addition
                              > is the last line, which shows you that indeed the URI is null if you load
                              > from string instead of from file:
                              > Dim xmldoc As New MSXML2.DOMDocum entClass()
                              > Dim xsldoc As New MSXML2.DOMDocum entClass()
                              > xmldoc.load("te st.xml")
                              > xsldoc.load("te st.xsl")
                              > ' xsldoc.loadXML( xsldoc.xml)
                              > Console.WriteLi ne(xmldoc.trans formNode(xsldoc ))
                              > Console.WriteLi ne(xsldoc.url)
                              >
                              > Note that count() returns the same result no matter if you comment out the
                              > string-load line or not.[/color]

                              MSXML XSLT implementation is based on completely different architecture
                              than .NET - it's fully DOM based, everything is loaded into DOM, so
                              there is always XSLT source available. That's not always the case when
                              XSLT is compiled (e.g. to bytecode in Xalan or MSIL in .NET 2.0).
                              Once again - if you compile C++ to exe, would you expect to get source
                              C++ сode running the exe?
                              [color=blue]
                              > I would enjoy very much to stop using MSXML, but it seems I cannot since it
                              > is the only platform that provides the functionality I need.[/color]

                              Basically I don't care, I just wanted to say that's a piece of cake to
                              get the same behaviour in .NET.

                              --
                              Oleg Tkachenko [XML MVP]

                              Comment

                              Working...