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

Select Data for individual child node

Subject: Select Data for individual child node
From: Rashi Bhardwaj <rashi.bhardwaj@xxxxxxxxx>
Date: Tue, 23 Nov 2010 17:29:27 +0530
 Select Data for individual child node
Hi All,

I m stuck in between to some issue, please help me out....

Input xml:

<test>
<a>
<b name ='1'></b>
<b name ='2'></b>
<b name ='3'>
<c>aaa</c>
</b>
<b name ='4'>
	<c>bbb</c>
	<c>ccc</c>
</b>
<b name ='4'>
	<c>dddd</c>
	<c>eeee</c>
</b>
</a>
<a>
<b name ='1'></b>
<b name ='2'>
<c>fffff</c>
</b>
<b name ='3'></b>
<b name ='4'>
	<c>gggg</c>
</b>
</a>
</test>

Xsl used:

<xsl:template match="/">
		<html>
			<body>
			<table>
				<tbody>
					<tr>
						<th>
						<xsl:value-of select="$CustomSelect"/>
						</th>
						<th>
						</th>
					</tr>
				</tbody>
			</table>
			</body>
		</html>
	</xsl:template>
	<xsl:variable name="CustomSelect">
			<xsl:text>position: </xsl:text>
				<xsl:call-template name="test">
				</xsl:call-template>
		</xsl:variable>
		<xsl:template name="test">
  <xsl:call-template name="test2">
  <xsl:with-param name="node" select="//b[c][not(@name
=preceding::b[child::c]/@name)]/@name"/>
    </xsl:call-template>
<xsl:template name="test2" match="*" mode="test2">
		<xsl:param name="node"/>
		<xsl:for-each select="//b[c][not(@name
=preceding::b[child::c]/@name)]/@name">
						<xsl:variable name="InitialList">
				<xsl:for-each select="//c[1][ancestor::b/@name=$node]">
							<xsl:text disable-output-escaping="no">&apos;</xsl:text>
							<xsl:value-of select="./text()"/>
							<xsl:text disable-output-escaping="no">&apos;, </xsl:text>							
				</xsl:for-each>
							</xsl:variable>
			<xsl:value-of select="concat('[',substring($InitialList, 1,
string-length($InitialList)-2), ']')"/>
						
							</xsl:for-each>
	</xsl:template>


output i m getting:

<th>position: ['aaa', 'bbb', 'ccc', 'dddd', 'eeee', 'fffff',
'gggg']['aaa', 'bbb', 'ccc', 'dddd', 'eeee', 'fffff', 'gggg']['aaa',
'bbb', 'ccc', 'dddd', 'eeee', 'fffff', 'gggg']</th>

Desired output:

<th>position: ['aaa'],['bbb', 'ccc', 'dddd', 'eeee', 'gggg'], ['ffff']</th>

That is for b(@name='3'), there is only one 'c' in the complete xml,
so the first square bracket contains 'aaa'. Similarly, for
b[@name='4'], there are four c elements in the complete xml, i.e. bbb,
ccc; dddd, eeee and gggg, so it was listed in second sq brackets.

Please let me know  is this possible........please help me out..........

Thanks....


-- 


Rashi Bhardwaj

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.