Home
TeamSite
Why document() couldn't fetch an xml file with $URL_PREFIX?
System
I defined a File datum pointing to a xml on TeamSite:
Its value turns to $URL_PREFIX/path_to_xml_file
Then in the component xsl, using the below code to fetch this file,
document('$URL_PREFIX/path_to_xml_file')
It's resolved to the below path during transformation, but couldn't fetch back the file successfully.
document('/iw/cci/meta/no-injection/iw-mount/default/main/ABC/WORKAREA/Shared/path_to_xml_file')"
If I hardcoded the acutal path on local file system as below, instead of using $URL_PREFIX, it works.
document('/iwmnt/default/main/ABC/WORKAREA/Shared/path_to_xml_file')
But this kind of hardcode is not allowed since during deployment the actual path on file system will change. Anybody can help me out? Why document() couldn't fetch a file with page token, which is supposed to work? Thanks in advance.
Find more posts tagged with
Comments
RonaldV
Hi,
the $URL_PREFIX is evaluated AFTER the xslt-transformation. So when the document() call is executed the $url-prefix is not yet replaced.
WorkspaceLogFile.png
WorkspaceLogFile(ExtensionsHidden).png
ConsoleOutDebugging.png
(Topic_39272)OS_BIRT_4.5.0_ChangeExistingSortDirection.rptdesign
Bowker
I totally agree - if you find a way to implement this without jumping through too many hoops - please post it back here.
vivek_cms
Hi,
Can you tell me where you are using the document() function. Whether it is a javascript or in xsl you are directly calling that function. Can you send your entire xsl code. So that i can understand the issue in detail and provide you the solution.
Thanks,
Vivek
Migrateduser
Thanks much for all of you. Yes, I believe that's the reason.
It's a call from xsl of a component instead of js. Since there is some customer information in code, I post the corresponding snippet below,
<xsl:variable name="xmlFile" select = Properties/Data/Datum[
@ID=
'xmlFile']" />
<xsl:variable name="xml" select="document($xmlFile)" />
<xsl:copy-of select="$xml" />
ID=xmlFile points to a File Datum which value turns to $URL_PREFIX/path_to_xml_file.
Then I tried to use the URL of a xml with document() function. The interesting thing is that the below code works well on
www.w3schools.com
site.
<xsl:variable name="xml" select="document('
http://www.w3schools.com/XML/note.xml?test=1')"
/>
<xsl:copy-of select="$xml" />
But if I put the exactly same code in the TeamSite component, it doesn't work! Any insight on it?
Also which TS log file can I refer to find out issues during component rendering/XSL transformation?
Thanks very much!
Acetao
Bowker
On the LiveSite server, you can look at
(your path may [will] be different from ours)
/opt/interwoven/LiveSiteDisplayServices/runtime/tomcat/logs/livesite.runtime.log
/opt/interwoven/LiveSiteDisplayServices/runtime/tomcat/logs/catalina.out
No guarantee that there will be anything worth while there, but it's worth a look.
BTW - the way we got around this was to create a site controller that looks at the server's host name, and does a look-up in a config that then populates some external 'datums' for environment, site name, mode (preview, ...), LSCS server name, and some other 'useful' information at XSL time.
RonaldV
You might want to try this tip from page 81 of the Sp-guide:
Using in Components
You can include the XSL templates using URL syntax to uniquely name the includes.
Autonomy uses the resolver mechanism to reference these files from the local system.
For more information, go to
http://xml.apache.org/commons/components/resolver/resolver-article.html
.
Use the following formats to include XSL templates:
http://www.interwoven.com/livesite
[relative file path].xsl
This URL syntax pulls files from the class path (relative to the com.interwoven package). If you have global static includes, you could put them in your customer toolkit and use this syntax to add them to your XSL. This syntax is provided for XSL files installed with the product.
http://www.interwoven.com/custom
[relative file path].xsl
This URL syntax pulls files from the TeamSite work area of the current site.
Migrateduser
Ronald and Dan, thanks a lot for your reply and tips. I will look into them to find a way to go.
As for the logs, there is no LiveSiteDisplayServices directory in the dev env. I suppose when previewing a component, LSDS is not mandatory. Should I take a look at the log of SitePubliser? No idea about where is that log.
Another issue of this function is that even I can use document() in XSL to read xml file (in my case, it's a XHTML) with hardcoded local path, XSL transformation fails if there is speical character '&' inside the content. E.g. if the content has the below information:
<a href="
http://aaa.bbb.com/index.php?s=99&item=8888"></a>
XSL will look on '&' as starting of an escaped entity, and then it turns to an error. (I haven't found the log, but get this observation through a few tests.)
Any insight on this issue? Thanks very much.
Snap 2016-05-27 at 08.49.35.png
HideLegendEntry.rptdesign
Migrateduser
The below code works. Thanks a lot for Ronald's tip! Yeah, TeamSite uses URL resolver mechanism.
<xsl:variable name="xml" select="document(
http://www.interwoven.com/custom
[relative file path].xml)" />
<xsl:copy-of select="$xml" />
I also believe using site controller as Bowker suggested will work, although I haven't tried it.
Due to the issue caused by the speical character '&' inside the content (it's actually a html file), it's still a blocker to use document() function.
It's appreciated if anybody can shed light on it.
Bowker
replace & with & in the URI and you should be ok.
Migrateduser
Thanks, Bowker. This means to add additional scripts to do the conversion on contents, which would be a seperate procedure besides component rendering. Or I'd use controller (Java) to hook this conversion into the component rendering. Is there any best practice?
Gantt.png
Gantt_as_expected.png
Bowker
Try something like this in your XSL script:
You may have to play with the exact number of amp; and & but you will get there.
[PHP]
(Note: You might have other exclude-result-prefixes and xmlns attributes)
[/PHP]
Migrateduser
But the challenge is that document() will fail first when reading the contents with & inside, so I cann't get to do this conversion in the component xsl script.
Bowker
If the contents of what's coming back has a & in it then you have a couple of choices -
1) (obviously) remove the & and/or replace with &
2) put <![CDADA[.....]]> around the text
2) use a different method than document() .. like....
(All disclaimers in place - This worked for me on my test machine, it probably will not work for you as is on your machine. I hold no responsibility if you try to use this and it works or doesn't work. If you move this in to production, don't call me if it blows up. Again - it worked for me, it might work for you.
(To be honest I have not tried this from the LiveSite engine, but from a standard install of XALAN it worked)
If anyone tries this and it works/doesn't work I would be interested in knowing your results.
This code will go fetch content at any URL. XML, HTML, Flat text, Junk with special characters...it doesn't matter.
[PHP]
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="
http://xml.apache.org/xalan"
xmlns:url="xalan://java.net.URL"
xmlns:conn="xalan://java.net.URLConnection"
xmlns:isr="xalan://java.io.InputStreamReader"
xmlns:br="xalan://java.io.BufferedReader"
exclude-result-prefixes="xalan url conn isr br"
>
buffered reader not ready
[/PHP]
Migrateduser
Thanks Dan for the sharing of the detailed code. It's awesome!
The workaround I apply now is to use ajax instead of document() to bypass the obstable. The outline of the code is as below.
- The source file with speical characters is configurable by datum;
- Use ajax to fetch it;
- then proceed(data) js function is to do any transformation and then insert into proper place in the DOM.
[PHP]
<script language="JavaScript" type="text/javascript">
$(document).ready(function(){
$.ajax({
type : "GET",
url: '
',
success: function(data) {
proceed(data);
},
error : function() {
alert("Sorry, ...");
}
});
});
</script>[/PHP]
Bowker
I'm a bit fuzzy on my "cross domain" issues with dealing with AJAX calls but I believe your solution has limitations that the data needs to live on the same server as the original server for the page.
The solution I provide also allows for servers not publicly viewable to supply data.
CalendarReport with Multi-Day Events Year v2__cwong.rptdesign
Migrateduser
Hi Dan,
Yes, you are right. AJAX has the limitation to only fetch info from the same server. Your great posts on this topic are really appreicated!
I will keep this thread for addtional 2 weeks for further input if any from anybody, and then close it for I think we already found the solution/workaround for the issue.