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 July 31st, 2007, 04:24 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default vbscript + xsl:variable

i can access the variable in the vbscript tag from xsl variable,and then store in vbscript variable, but how can i asign the value back to xsl variable?

is that possible for me to do that?

bcuz i need to compare two variable(previous & current) inside for-each

Reply With Quote
  #2 (permalink)  
Old July 31st, 2007, 04:36 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT variables are immutable.

What are you actually trying to achieve?

And what environment are you running in?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old August 1st, 2007, 10:35 AM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sample xml:
<LINE><DATA>Journal1</DATA><DATA>Journal1</DATA><DATA>3000</DATA><DEBIT>400</DEBIT><CREDIT></CREDIT></LINE>
<LINE><DATA>Journal1</DATA><DATA>Journal1</DATA><DATA>4000</DATA><DEBIT></DEBIT><CREDIT>400</CREDIT></LINE>

sample xsl:
<xsl:tempalte match="/">
 <xsl:for-each select="//LINE">
   <xsl:if test="string(DATA)">
  <xsl:variable name="vv"><xsl:value-of select="DATA"/></xsl:variable>
   <HTML>
   <xsl:apply-templates select="//REPORT"/>
   <BODY>
......

right now, the code will print <HTML> tag everytime //DATA contains somethings. how can i set a condition or set variable to make a comparison between previous DATA content with current DATA content?
because i can't store variable to compare, however, is there any aproach to store and access data?

i was thinking using vbscript or javascript,but didn't work. also i look up for <xsl:script> but the sample in the website didn't see to work.

any suggestion?

Reply With Quote
  #4 (permalink)  
Old August 1st, 2007, 10:49 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>right now, the code will print <HTML> tag everytime //DATA contains somethings

Actually, it will output one <HTML> element for every LINE element in your source document. That's what xsl:for-each does.

>how can i set a condition or set variable to make a comparison between previous DATA content with current DATA content?

You can compare a node with its immediately preceding sibling using

<xsl:if test=". = preceding-sibling::*[1][self::DATA]">

or with all preceding siblings using

<xsl:if test=". = preceding-sibling::DATA">

For grouping in XSLT 2.0, use xsl:for-each-group. If you're stuck with 1.0, it's much more difficult, read about it at http://www.jenitennison.com/xslt/grouping

But I'd suggest learning the basics first. Your first question suggests you haven't understood things like for-each, template rules, the meaning of "//", etc; don't try any fancy grouping until you've mastered these foundations.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old August 1st, 2007, 10:52 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Oh, and by the way, don't try mixing XSLT with other languages until you've got a lot further down the learning curve. Mixing languages is difficult. It's always tempting if you're in a foreign country to get your coffee from Starbucks because it tastes familiar, but it's a mistake - they brew it much better in most places.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #6 (permalink)  
Old August 1st, 2007, 11:23 AM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

so is there any solution for that?
or any other way that i can achieve it?

Reply With Quote
  #7 (permalink)  
Old August 1st, 2007, 12:15 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I thought I made it very clear that there was a solution and that it wasn't really very difficult. But you obviously need to spend a few days reading about the basic principles of the language before you do any more. Read some tutorials, study the examples, and come back when you have more specific questions.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #8 (permalink)  
Old August 1st, 2007, 12:49 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry, i didn't notice that you replied aleady.
i was confused by the color of the post!!
thanks, let me test it

Reply With Quote
  #9 (permalink)  
Old August 1st, 2007, 01:44 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

 
Quote:
quote:Starbucks because it tastes familiar, but it's a mistake - they brew it much better in most places.

I thought I was the only one! Great analogy!

Reply With Quote
  #10 (permalink)  
Old August 2nd, 2007, 11:44 AM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

problem solved, thanks

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
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
The difference between xsl:variable and xsl:param NEO1976 XML 2 July 24th, 2006 06:05 AM
pass java variable to xsl variable kathy1016cats XSLT 1 June 14th, 2006 06:23 PM
xsl variable in xsl tag? di98svpa XSLT 1 February 10th, 2006 01:41 PM



All times are GMT -4. The time now is 06:49 PM.


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