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 April 14th, 2010, 03:08 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Set Variable Name To Position()

Hello.

I need to create variables whose names are the value of the Position() function. I'm within a for-each loop and for each occurrence of an element I want to create a variable.

What I'm trying to accomplish is create some variables(one for each occurrence of <RCDATALINE>), set their values to the <TRC> value and have access to all these created variables.

So, with the following XML:
<RCDATALINE>
<TRC>90</TRC>
<OVERRIDE>Y</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC>
<OVERRIDE>Y</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC>
<OVERRIDE>N</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC>
<OVERRIDE>N</OVERRIDE>
</RCDATALINE>

And the following XSLT code:
<xsl:for-each select="RCDATALINE">
<xsl:variable name=Position()>
<xsl:choose>
<xsl:when test=”TRC[.!=''] and OVERRIDE[.!='Y']”>
<xsl:value-of select=TRC>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=''>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

I now, within this for-each loop, want to check that the current <TRC> does not equal any of the values of these variables.

I have a post where I'm trying to accomplish not printing out previous same <TRC> values using "preceding-sibling" but am unable to get that to work under certain conditions. I'm now trying to use variables that have all <TRC> values stored in them (if <OVERRIDE> is not Y).

Here's the link to that post.
Code To Use the Position Function

I'm new to XSLT so don't know if I'm just wasting my time going this route!

Thanks,
Rita
 
Old April 14th, 2010, 03:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

As with all other compiled programming languages that I know of, variables have a static (compile-time) declaration, and a dynamic (run-time) initialization. So the existence and scope of a variable are things you define statically (they cannot depend on data you read at run-time). Only the value of the variable can depend on run-time data. In other words, you cannot create variables at run-time, and you cannot create a variable number of variables depending on the input data.

Stick to the approach you were using in your other thread. You may have the detail wrong, but it's the right general approach.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 14th, 2010, 03:40 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Thanks Michael - much appreciated!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object variable not set or With Block not set brucechess BOOK: Beginning VB.NET Databases 1 March 3rd, 2009 07:30 AM
Set Form DataSet Position to DataGrid Selection robzyc C# 2 September 9th, 2007 04:28 AM
Object variable or With block variable not set haidee_mccaffrey Classic ASP Professional 5 March 8th, 2007 03:34 PM
Set window position using button blkskullwork Javascript 5 January 18th, 2007 04:51 PM
How to set cursor position in a textbox? zayasv VB.NET 2 April 29th, 2006 07:09 AM





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