Ankit.Hegde Posted November 24, 2006 Share Posted November 24, 2006 Hi, I am a bit new to xslt. I am trying to use the document function to parse through a xml and get node values for my xsl stylesheet. E.g. xmlsample.xml<? xml version="1.0" encoding="utf-8" ?><RootNode><Node1>value1</Node1><Node2>value2</Node2></RootNode> ********And in my xsl stylesheet I try to get the values ******<xsl:variable name="var1" select="document('sample.xml')/RootNode/Node1"/>....<OutputNode><xsl:value-of select="$var1"/></OutputNode>******But my output that I am getting: <OutputNode/>for the document function i even tried giving the path name: i.e. document('<Drive>:\Folder\sample.xml') - but I am not getting any output. I am not able to figure out where I am going wrong, If I need to place a file in some particular path . Please do let me know. Thanks in advance. Link to comment Share on other sites More sharing options...
boen_robot Posted November 24, 2006 Share Posted November 24, 2006 First things first. You do know that this function should be used for parsing XML documents other then the currently transformed one, right? Not needed otherwise.Try placing the XML, the XSLT and the sample.xml file in one folder and see if it works then. If it does, try moving each of the files in a different folder to see how does your processor resolve URIs. That is, relative to the XML, to the XSLT or to the processor itself. Link to comment Share on other sites More sharing options...
Ankit.Hegde Posted November 27, 2006 Author Share Posted November 27, 2006 First things first. You do know that this function should be used for parsing XML documents other then the currently transformed one, right? Not needed otherwise.Try placing the XML, the XSLT and the sample.xml file in one folder and see if it works then. If it does, try moving each of the files in a different folder to see how does your processor resolve URIs. That is, relative to the XML, to the XSLT or to the processor itself.Hi, Thanks for the reply. I am using the file1.xsl as a Map (In Biztalk- am not sure how much that would help) to convert an Input.xml to Output.xml and trying to access values from sample.xml. And I am trying to access values of another xml file( so the usage of document function is needed).I have tried placing the xml and xsl files in the same folder, but havent been successful to extract the values.So I am not sure about any other indirect dependencies that may be causing the problem.A very basic doubt. How can I test my XSL code directly on the xml files. I havent ever tried that as I am using xslt for the first time. Could you suggest a link or so. Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted November 27, 2006 Share Posted November 27, 2006 Biztalk is your processor you mean? Huh... whatever...Try to see if document() is supported there to begin with. Like this: <xsl:choose><xsl:when test="function-available('document')"><xsl:variable name="var1" select="document('sample.xml')/RootNode/Node1"/>....<OutputNode><xsl:value-of select="$var1"/></OutputNode></xsl:when><xsl:otherwise><OutputNode>Document is not supported.</OutputNode></xsl:otherwise></xsl:choose> If that does't work (that is, if document() is supported, but the output is still the same), try giving absolute filepath fot the XML using the file:// protocol:file:///D|/folder/sample.xmlthat is if we suppose your XML is on D: drive of course. Link to comment Share on other sites More sharing options...
Ankit.Hegde Posted November 28, 2006 Author Share Posted November 28, 2006 Hi, I tried as you said, And the function-available method provides me a true value. That proves that the document() function can be used within the BizTalk Map(xsltMap.xsl) . And as mentioned I did try giving the absolute path using the file protocol: document('file:///E|/Folder/Sample.xml')/RootNode/Node1. But still it returns me the same value of <OutputNode/>. I am not able to figure out where I am going wrong. The same path on the command prompt takes me to the right location( Folder/Sample.xml) as the file is opening. Do I need to take care of any security/Perm access issues to the folder? as I have tried giving all kinds of path( absolute, file protocol path). I am not sure of how to use a relative path. I tried to provide a relative path relative to the map.xsl (But the current position might be somewhere within input xml also?) So can you tell me if I try using relative path, what must I take the point of reference as. And I am not sure why the document() function is not able to select the file despite usage of absolute path. :)Because here if the document method works, I would have to make the path to pick the xml file as relative to the project(somecomponent) as the project would be deployed at another place( there absolute path may not be the best solution. Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted November 28, 2006 Share Posted November 28, 2006 The problem may be some sort of bug in biztalk. Try running the same XML and XSLT pair with IE or perhaps Firefox (NOT in Opera!). If you have some sort of server side scripting processor (PHP5's libxslt for example), try using it too. It should work in all of them. Link to comment Share on other sites More sharing options...
Ankit.Hegde Posted November 28, 2006 Author Share Posted November 28, 2006 Hi, Thanks!! I think it may be a bug. I got to confirm on that. Though I tested the document function using DotNet. I had an input xml, map.xsl, output.xml,sample.xml. Using Transform I could simulate the mapping and then the document function works fine and I get <OutputNode> Some Value </OutputNode>. But the same when tried using BizTalk Map Tool dint work. I dint get about what you mentioned "Running same XML and XSLT pair with IE". I will try to find that out. Link to comment Share on other sites More sharing options...
boen_robot Posted November 28, 2006 Share Posted November 28, 2006 What I meant was to open input.xml in IE. If that XML has<?xml-stylesheet type="text/xsl" href="file1.xsl"?>The MSXML3 processor which IE is using will be started and what you'll see will be the result of an XSLT transformation using the file1.xsl file.Running the same file with FF will start the Transformiix XSLT processor.In other words, I just meant "use another XSLT processor". Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now