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 July 31st, 2007, 04:24 PM
Authorized User
 
Join Date: Jul 2007
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

 
Old July 31st, 2007, 04:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old August 1st, 2007, 10:35 AM
Authorized User
 
Join Date: Jul 2007
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?

 
Old August 1st, 2007, 10:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old August 1st, 2007, 10:52 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old August 1st, 2007, 11:23 AM
Authorized User
 
Join Date: Jul 2007
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?

 
Old August 1st, 2007, 12:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old August 1st, 2007, 12:49 PM
Authorized User
 
Join Date: Jul 2007
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

 
Old August 1st, 2007, 01:44 PM
Friend of Wrox
 
Join Date: Jul 2006
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!

 
Old August 2nd, 2007, 11:44 AM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

problem solved, thanks






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





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