p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   vbscript + xsl:variable (http://p2p.wrox.com/showthread.php?t=60693)

lscjtw July 31st, 2007 04:24 PM

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


mhkay July 31st, 2007 04:36 PM

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

lscjtw August 1st, 2007 10:35 AM

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?


mhkay August 1st, 2007 10:49 AM

>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

mhkay August 1st, 2007 10:52 AM

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

lscjtw August 1st, 2007 11:23 AM

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


mhkay August 1st, 2007 12:15 PM

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

lscjtw August 1st, 2007 12:49 PM

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


bonekrusher August 1st, 2007 01:44 PM

 
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!


lscjtw August 2nd, 2007 11:44 AM

problem solved, thanks



All times are GMT -4. The time now is 07:04 AM.

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