[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Conditional Assigining

Subject: Re: Conditional Assigining
From: "Sri ni" <srini75@xxxxxxxxxxx>
Date: Thu, 17 May 2001 10:50:04 -0000
xsl param reassign values
Hi jeni,

Thank you very very much for the reply. I really got struck with a serious problem and require your valuable help (as usual) to solve it.

Here comes my XML FILE
<xslTutorial >

<section>
<sectionID>1</sectionID>
<parentID>0</parentID>
<text>section 1</text>
</section>

<section>
<sectionID>2</sectionID>
<parentID>0</parentID>
<text>section 2</text>
</section>

<section>
<sectionID>3</sectionID>
<parentID>1</parentID>
<text>section 1.1</text>
</section>


<section> <sectionID>4</sectionID> <parentID>1</parentID> <text>section 1.2</text> </section>

<section>
<sectionID>5</sectionID>
<parentID>3</parentID>
<text>section 1.1</text>
</section>

<section>
<sectionID>6</sectionID>
<parentID>2</parentID>
<text>section 2.1</text>
</section>

<section>
<sectionID>7</sectionID>
<parentID>2</parentID>
<text>section 2.2</text>
</section>

<section>
<sectionID>8</sectionID>
<parentID>6</parentID>
<text>section 2.1.1</text>
</section>
</xslTutorial>

My xsl file read as follows:
-----------------------------
<xsl:template match="First">
	<xsl:for-each select="Section[parentID='0']">
		<xsl:variable name="ID" select="sectionID"/>
		<xsl:call-template name="recur">
			<xsl:with-param name="id">
				<xsl:value-of select="sectionID" />
			</xsl:with-param>
			<xsl:with-param name="pid">
				<xsl:value-of select="parentID" />
			</xsl:with-param>
			<xsl:with-param name="textvalue">
				<xsl:value-of select="text" />
			</xsl:with-param>
		</xsl:call-template>
		<xsl:for-each select="../Section[parentID=$ID]">
		sub
			<xsl:variable name="ID" select="sectionID"/>
			<xsl:call-template name="recur">
				<xsl:with-param name="id">
					<xsl:value-of select="sectionID" />
				</xsl:with-param>
				<xsl:with-param name="pid">
					<xsl:value-of select="parentID" />
				</xsl:with-param>
				<xsl:with-param name="textvalue">
					<xsl:value-of select="text" />
				</xsl:with-param>
			</xsl:call-template>
			<xsl:apply-templates select="child::*/section" />
			<xsl:text>
			</xsl:text>
		</xsl:for-each>
		<!--after functiion
		<xsl:call-template name="recur">
				<xsl:with-param name="id">
					<xsl:value-of select="sectionID" />
				</xsl:with-param>
				<xsl:with-param name="pid">
					<xsl:value-of select="parentID" />
				</xsl:with-param>
				<xsl:with-param name="textvalue">
					<xsl:value-of select="text" />
				</xsl:with-param>
			</xsl:call-template>-->
		</xsl:for-each>

</xsl:template>


<xsl:template name="recur"> <xsl:param name="id" /> id <xsl:value-of select="$id"/> <xsl:param name="pid" /> pid <xsl:value-of select="$pid"/> <xsl:param name="textvalue" /> text <xsl:value-of select="$textvalue"/>

</xsl:template>
<xsl:template name="recur1">
	<xsl:param name="id" />
	id <xsl:value-of select="$id"/>
	<xsl:param name="pid" />
	pid <xsl:value-of select="$pid"/>
	<xsl:param name="textvalue" />
	text <xsl:value-of select="$textvalue"/>

</xsl:template>

</xsl:stylesheet>


My output is as follows: --------------------------- <?xml version="1.0" encoding="UTF-8"?>

	id 1
	pid 0
	text Section 1
		sub

	id 5
	pid 1
	text Section 1.1

	id 2
	pid 0
	text Section 2
		sub

	id 6
	pid 2
	text Section 2.1

	id 6
	pid 2
	text Section 2.1.1



As you can see, i am not getting only the first level of output (ie. 1, 1.1 and 2, 2.1, 2.1.1). I am not getting the second level of output ( ie 1, 1.2 and 2, 2.2) AT ALL.

can you please please help me out from this??. I really got struck with this for almost 2 days.

thanks jeni for your patience,
Srini


From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: "Sri ni" <srini75@xxxxxxxxxxx>
CC: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Conditional Assigining
Date: Wed, 16 May 2001 19:41:01 +0100

Hi Sri,

> <xsl:variable name="ID">-1</xsl:variable>
> <xsl:for-each select="Section[parentID='0']">
>         <xsl:if test="$ID=-1">
>                 <xsl:variable name="ID" select="sectionID" />
>         </xsl:if>
> id <xsl:value-of select="$ID"/>

You cannot use variables in this way within XSLT. A variable's scope
is limited to its following siblings and their descendants, and you
cannot reassign a different value to the variable (unless you use an
extension element like saxon:assign).

If you want to get the value of the sectionID of that first Section
element, then that's what you should set the value of the variable to:

<xsl:variable name="ID" select="Section[parentID = '0'][1]" />

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread
  • RE: nested templates?, (continued)
        • Tim Watts - Wed, 16 May 2001 19:57:58 -0400 (EDT)
        • Alex Black - Wed, 16 May 2001 20:13:03 -0400 (EDT)
    • Jeni Tennison - Wed, 16 May 2001 14:45:37 -0400 (EDT)
    • Sri ni - Thu, 17 May 2001 05:01:59 -0400 (EDT)
    • Sri ni - Thu, 17 May 2001 06:49:56 -0400 (EDT) <=
    • Sri ni - Thu, 17 May 2001 07:20:34 -0400 (EDT)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.