Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2008, 04:55 AM
Authorized User
 
Join Date: Oct 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript functions and xslt 1.0 variable

How can I interact with javascript functions...using xslt...

I want to get xml file name using xslt..[Is that possible? if there is no attribute for the same; if yes please advice.]

for that I want to add javascript which will work while loading/processing the xml file and give me the file name.

my javascript code is like below...
which works fine in html
************************************************** *****************
<script language="JScript">
 function returnDocument()
  {
   var file_name = document.location.href;
   var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
   name = file_name.substring(file_name.lastIndexOf("/")+1, end);
   alert(name);
 }
</script>
************************************************** *****************

how can i implement the same in xslt for getting xml file's name?

example
mytest.xml [should be any name [not knowing before transform]]
mytest.xsl

while processing mytest.xsl on mytest.xml code automatically get file name of xml file i.e. "mytest" and should store in xslt inside a variable.


please help.

I am Desperately looking to this.

Thanks in advance.

Cheers
Mahesh:(
 
Old October 30th, 2008, 05:00 AM
Authorized User
 
Join Date: Sep 2008
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi,

may be this link may help u

http://www.xsltfunctions.com/xsl/c0008.html

Raj

 
Old October 30th, 2008, 06:12 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Use document-uri() function as shown below:
<xsl:variable name="file"><xsl:value-of select="document-uri(/)"></xsl:value-of></xsl:variable>

<xsl:template match="/">
<xsl:value-of select="document-uri(/)"></xsl:value-of>
<xsl:value-of select="$file"></xsl:value-of>
</xsl:template>


------
Rummy
 
Old October 31st, 2008, 12:05 AM
Authorized User
 
Join Date: Oct 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for help.

Now my problem is,

I can use only xslt 1.0 [Our mechanism cant support xslt 2.0]

pls suggest is there any other way using xslt 1.0.

thanks again.

Mahesh
 
Old October 31st, 2008, 03:44 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

How do you pass the xml file to the stylesheet? If you run any exe (like instant saxon.exe, transform.exe) through command line, then the xml file name can be taken as parameter and inside the stylesheet the parameter value can be taken using <xsl:value-of select="">.

------
Rummy
 
Old October 31st, 2008, 04:18 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 1.0 the only way for the stylesheet to discover the URI of the source document is by passing it explicitly as a stylesheet parameter from the calling application.

(Or, of course, you might be able to arrange for the XML source document to include its own URI in the content.)

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old November 3rd, 2008, 04:09 AM
Authorized User
 
Join Date: Oct 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I cant pass the value explicitly as there are hundreds of xml files which are using only single xslt..

i am creating one html output file from all these xml input files.

And inside that html file; there is link for each generated html file [which is transformed by xml by other xslt]; which "SHOULD" be the file name only.

can I use javascript while processing on xml file and store filename in variable of xslt.

please suggest.

thanks for all your help.

Mahesh
 
Old November 3rd, 2008, 05:28 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

No. If you show the process in more detail then I'm sure that there must be somewhere where you can inject the filename.

--

Joe (Microsoft MVP - XML)
 
Old November 3rd, 2008, 05:36 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>i am creating one html output file from all these xml input files.

So, how does your application know what XML input files to process? At the point where it makes that decision, it knows the URI of the input file, so it can pass it to the transformation.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old November 4th, 2008, 03:44 AM
Authorized User
 
Join Date: Oct 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all your help.

Let me show what I am doing;

1] I am using Arbortext Publishing Engine.
2] I am loading the .ditamap in arbortext.
3] .ditamap file contains only all href for the topics.
4] I am using xsl which should produce 1 single html file.
5] which should having hrefs for all other html files which are
   created previously by some other xslt [on the basis of filename
   (match used in this is very simple and for element which is inside
    .dita file and also that match not work here) ].
6] For that purpose I need file name in href so I can link
   appropriate html files.

Thanks.

Mahesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT and JavaScript Variable kwilliams XSLT 5 April 21st, 2008 12:05 PM
assign XSLT variable to a wml variable arunagottimukkala XSLT 2 October 19th, 2007 05:15 AM
storing Javascript variable to ASP variable rupen Classic ASP Basics 5 April 10th, 2007 07:06 AM
assign javascript variable to asp variable manjunath_c_k Classic ASP Basics 1 September 14th, 2006 07:35 AM
javascript functions Moharo Javascript 1 September 23rd, 2003 01:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.