Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 30th, 2008, 04:55 AM
Authorized User
 
Join Date: Oct 2008
Location: Pune, Maharashtra, India.
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:(
Reply With Quote
  #2 (permalink)  
Old October 30th, 2008, 05:00 AM
Authorized User
 
Join Date: Sep 2008
Location: , , Singapore.
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

Reply With Quote
  #3 (permalink)  
Old October 30th, 2008, 06:12 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
  #4 (permalink)  
Old October 31st, 2008, 12:05 AM
Authorized User
 
Join Date: Oct 2008
Location: Pune, Maharashtra, India.
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
Reply With Quote
  #5 (permalink)  
Old October 31st, 2008, 03:44 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
  #6 (permalink)  
Old October 31st, 2008, 04:18 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #7 (permalink)  
Old November 3rd, 2008, 04:09 AM
Authorized User
 
Join Date: Oct 2008
Location: Pune, Maharashtra, India.
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
Reply With Quote
  #8 (permalink)  
Old November 3rd, 2008, 05:28 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #9 (permalink)  
Old November 3rd, 2008, 05:36 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #10 (permalink)  
Old November 4th, 2008, 03:44 AM
Authorized User
 
Join Date: Oct 2008
Location: Pune, Maharashtra, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:05 PM.


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