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 November 13th, 2007, 05:53 AM
Authorized User
 
Join Date: Aug 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Variable reassignment

I am trying to get the last value of a series of values using variable reassignement. But, it's not working (see the code below) as variable reassignment is not possible in XSL. Also, we don't have arrays in XSL from where I can get the last value. Can anyone suggest an alternative approach?

<xsl:when test="../@refer_condition1='true' and ../@refer_condition2='true'">
                <xsl:variable name="cond"/>
                    <fo:table-cell border-style="thin"
                        number-columns-spanned="2">
                        <xsl:for-each select="parent::node()">
                            <xsl:for-each select="preceding-sibling::node()">
                                <xsl:if test="not(@condition='^')">
                                        <xsl:variable name="cond" select="@condition"/>
                                    </xsl:if>
                            </xsl:for-each>
                        </xsl:for-each>
                                <fo:block start-indent="0pt" font-family="Arial"
                                    language="EN-US" space-before="3pt"
                                    space-before.conditionality="retain" space-after="3pt"
                                    space-after.conditionality="retain" font-size="9pt"
                                    font-style="italic">
                                    <xsl:value-of select="$cond"/>
                                </fo:block>
                    </fo:table-cell>

 
Old November 13th, 2007, 06:04 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Try something like

<xsl:variable name="cond">
  <xsl:value-of select="../preceding-sibling::node()[not(@condition='^')][last()]" />
</xsl:variable>

/- Sam Judson : Wrox Technical Editor -/
 
Old November 13th, 2007, 06:20 AM
Authorized User
 
Join Date: Aug 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 Try something like

<xsl:variable name="cond">
<xsl:value-of select="../preceding-sibling::node()[not(@condition='^')][last()]" />
</xsl:variable>

/- Sam Judson : Wrox Technical Editor -/
Thanks for prompt reply Sam
but it's not working
I placed it in <fo:block> but it's not returning anything

<xsl:when test="../@refer_condition1='true' and ../@refer_condition2='true'">
                <xsl:variable name="cond"/>
                    <fo:table-cell border-style="thin"
                        number-columns-spanned="2">
                        <!--<xsl:for-each select="parent::node()">
                            <xsl:for-each select="preceding-sibling::node()">
                                <xsl:if test="not(@condition='^')">
                                        <xsl:variable name="cond" select="@condition"/>
                                    </xsl:if>
                            </xsl:for-each>
                        </xsl:for-each>
                                --><
                                fo:block start-indent="0pt" font-family="Arial"
                                    language="EN-US" space-before="3pt"
                                    space-before.conditionality="retain" space-after="3pt"
                                    space-after.conditionality="retain" font-size="9pt"
                                    font-style="italic">
                                    <xsl:value-of select="../preceding-sibling::node()[not(@condition='^')][last()]" />
                                </fo:block>
                    </fo:table-cell>

 
Old November 13th, 2007, 06:26 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well I don't know the format of your XML so can't really comment on whether my 'guess' at the correct xpath is right.

It was simply meant to show you the direction you could go in to get what you want. You're expected to fill in the final details.

/- Sam Judson : Wrox Technical Editor -/
 
Old November 13th, 2007, 06:31 AM
Authorized User
 
Join Date: Aug 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 Well I don't know the format of your XML so can't really comment on whether my 'guess' at the correct xpath is right.

It was simply meant to show you the direction you could go in to get what you want. You're expected to fill in the final details.

/- Sam Judson : Wrox Technical Editor -/
Your guess was correct I am trying to get the last preceding sibling of current node's parent where condition is not '^'. But I'm not sure about the syntax as I am new to XSL

Thanks anyways for your help



 
Old November 13th, 2007, 06:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It looks to me as if you are trying to get the last element among the preceding siblings of your parent that satisfies not(@condition='^').

In XPath that's

../preceding-sibling::*[not(@condition='^')][1]

Try to translate your description of the problem into an expression that describes it directly, forget about procedural logic like looping and assignment, it just makes your life more difficult.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 13th, 2007, 07:05 AM
Authorized User
 
Join Date: Aug 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 It looks to me as if you are trying to get the last element among the preceding siblings of your parent that satisfies not(@condition='^').

In XPath that's

../preceding-sibling::*[not(@condition='^')][1]

Try to translate your description of the problem into an expression that describes it directly, forget about procedural logic like looping and assignment, it just makes your life more difficult.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
THANKS A LOT Michael
You saved me. I had to submit the generated document to my client by evening.







Similar Threads
Thread Thread Starter Forum Replies Last Post
storing Javascript variable to ASP variable rupen Classic ASP Basics 5 April 10th, 2007 07:06 AM
Object variable or With block variable not set haidee_mccaffrey Classic ASP Professional 5 March 8th, 2007 03:34 PM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
object variable or with block variable not set Aoude BOOK: Beginning VB.NET Databases 1 February 24th, 2006 05:21 PM
Object variable or With block variable not set tparrish Classic ASP Databases 0 May 21st, 2005 06:48 AM





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