[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 09:01:29 -0000
id xsl
Thanks all for your help, but please help me to solve this problem.

Here is my xml
section.xml
----------------
	<Section>

<sectionID>1</sectionID>

<parentID>0</parentID>

<bulletinID>1</bulletinID>

<groupID>1</groupID>

<dictionaryID>1000</dictionaryID>

<text>Section 1</text>

</Section>


<Section>


<sectionID>2</sectionID>

<parentID>0</parentID>

<bulletinID>1</bulletinID>

<groupID>1</groupID>

<dictionaryID>1001</dictionaryID>

<text>Section 2</text>

</Section>

<Section>

<sectionID>5</sectionID>

<parentID>1</parentID>

<bulletinID>1</bulletinID>

<groupID>1</groupID>

<dictionaryID>1004</dictionaryID>

<text>Section 1.1</text>

</Section>


<Section>


<sectionID>11</sectionID>

<parentID>1</parentID>

<bulletinID>1</bulletinID>

<groupID>1</groupID>

<dictionaryID>1008</dictionaryID>

<text>Section 1.2</text>

</Section>

<Section>

<sectionID>10</sectionID>

<parentID>5</parentID>

<bulletinID>1</bulletinID>

<groupID>1</groupID>

<dictionaryID>1012</dictionaryID>

<text>Section 1.1.1</text>

</Section>


<Section> <sectionID>19</sectionID> <parentID>10</parentID> <bulletinID>1</bulletinID> <groupID>1</groupID> <dictionaryID>1012</dictionaryID> <text>Section 1.1.1.1</text> </Section> <Section>

<sectionID>6</sectionID>

<parentID>2</parentID>

<bulletinID>1</bulletinID>

<groupID>1</groupID>

<dictionaryID>1005</dictionaryID>

<text>Section 2.1</text>

</Section>


<Section>


<sectionID>12</sectionID>

<parentID>2</parentID>

<bulletinID>1</bulletinID>

<groupID>1</groupID>

<dictionaryID>1009</dictionaryID>

<text>Section 2.2</text>

</Section>


My xsl:
----------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="First"/>
</xsl:template>


<xsl:template match="First">
	<!--<xsl:for-each select="Section[parentID='0']"> -->
	<xsl:for-each select="Section">
	<xsl:variable name="ID" select="sectionID"/>
	<xsl:value-of select="text"/>
		<xsl:for-each select="../Section[parentID=$ID]">
			<xsl:value-of select="text"/><br/>
			<xsl:variable name="ID" select="sectionID"/>
<!--			currentID = <xsl:value-of select="$ID" />-->
		</xsl:for-each>
<!--		<xsl:variable name="ID" select="sectionID"/>
		sectionid afterloop= <xsl:value-of select="$ID" />-->
<!--		<xsl:variable name="ID" select="text"/>
		text afterloop = <xsl:value-of select="$ID" />-->

	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>


CURRENT OUTPUT: ----------------- id 1 pid 0 text Section 1

	id 5
	pid 1
	text Section 1.1

	id 10
	pid 5
	text Section 1.1.1

	id 19
	pid 10
	text Section 1.1.1.1


Desired Output =============== id 1 pid 0 text Section 1

	id 5
	pid 1
	text Section 1.1

	id 10
	pid 5
	text Section 1.1.1

	id 19
	pid 10
	text Section 1.1.1.1

	id 11
	pid 1
	text Section 1.2


I am able to loop through the first part of the xml but when it comes to the second part of the subsection i am not getting that output at all.


Can anyone please please help me out.

Thanks in advance,
Srini
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE:  Conditional Assigining
Date: Wed, 16 May 2001 17:15:17 +0100

>
> <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"/>
>
XSLT isn't a sequential programming language, you are trying to use it as if
it were. You can't do things in one iteration of xsl:for-each that affect
subsequent iterations, because there is no such thing as "subsequent" in a
non-sequential language. (See my XSLT Programmer's Reference for an essay on
the subject...)


Instead you want something like

<xsl:for-each select="Section[parentID='0']">
  <xsl:choose>
  <xsl:when test="preceding-sibling::Section[parentID='0']">
     <xsl:value-of select="preceding-sibling::Section[parentID='0'][1]"/>
  </xsl:when>
  <xsl:otherwise>-1</xsl:otherwise>
  </xsl:choose>
</xsl:for-each>

That works because it expresses the output as a function of the input.

Mike Kay


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

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.