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 September 2nd, 2009, 05:09 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try the below:
Code:
<xsl:key name="type" match="plan" use="@plantype"/>

<xsl:template match="/">
<html>

<head><title>Test</title></head>
<body>

<xsl:variable name="r" select="records"/>
<xsl:variable name="posi" select="//plan"/>
<xsl:for-each select="//plan[generate-id() = generate-id(key('type', @plantype)[1])]">

<table border="1" width="100%">
<tr>
<td></td>
<td><xsl:value-of select="@breadcrumb"/></td>
<td><xsl:value-of select="@breadcrumb"/></td>
</tr>
<xsl:for-each select="$posi[1]/field">
<xsl:variable name="p" select="position()"/>
<xsl:choose>
<xsl:when test="type = 'SectionTitle'">
<tr>
<td colspan='100%' bgcolor='#00BFFF'><xsl:value-of select="fieldtext"/></td>
</tr>
</xsl:when>
<xsl:when test="type = 'NormalField'">
<tr>
<!--td width='20%'><xsl:value-of select="fieldtext"/></td-->
<td width='20%' class="rowstyle1"><xsl:value-of select="fieldtext"/></td>
<!--td width='20%' bgcolor="{$style1}"><xsl:value-of select="fieldtext"/></td-->
<xsl:for-each select="$r/plan[generate-id() = generate-id(key('type', @plantype)[1])]">
<td><xsl:value-of select="field[$p]/fieldvalue" disable-output-escaping="yes"/></td>
</xsl:for-each>
<xsl:for-each select="//plan[generate-id() = generate-id(key('type', @plantype)[1])]">
<td><xsl:value-of select="'N/A'"/></td>
</xsl:for-each>

</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>

__________________
Rummy
The Following User Says Thank You to mrame For This Useful Post:
kokoness (September 2nd, 2009)
 
Old September 2nd, 2009, 06:30 AM
Authorized User
 
Join Date: Aug 2009
Posts: 31
Thanks: 16
Thanked 1 Time in 1 Post
Default

Code:
<xsl:for-each select="$r/plan[generate-id() = generate-id(key('type', @plantype)[1])]">
	<td>
		<xsl:value-of select="field[$p]/fieldvalue" disable-output-escaping="yes"/>
	</td>
</xsl:for-each>
The code above basically retrieves a plan regardless of plantype.

Assuming I have a variable $currentplantype (contains current plantype), what would I need to modify so that it will just iterate plans with the plantype of $currentplantype?

Last edited by kokoness; September 2nd, 2009 at 06:47 AM..
 
Old September 2nd, 2009, 06:49 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try the below:
Code:
<xsl:template match="/">
<html>

<head><title>Test</title></head>
<body>

<xsl:variable name="r" select="records"/>
<xsl:variable name="posi" select="//plan"/>
<xsl:for-each select="//plan[generate-id() = generate-id(key('type', @plantype)[1])]">
<xsl:variable name="plantype" select="@plantype"></xsl:variable>
<xsl:value-of select="$plantype"/>
<table border="1" width="100%">
<tr>
<td></td>
<td><xsl:value-of select="@breadcrumb"/></td>
<td><xsl:value-of select="@breadcrumb"/></td>
</tr>
<xsl:for-each select="$posi[1]/field">
<xsl:variable name="p" select="position()"/>
<xsl:choose>
<xsl:when test="type = 'SectionTitle'">
<tr>
<td colspan='100%' bgcolor='#00BFFF'><xsl:value-of select="fieldtext"/></td>
</tr>
</xsl:when>
<xsl:when test="type = 'NormalField'">
<tr>
<!--td width='20%'><xsl:value-of select="fieldtext"/></td-->
<td width='20%' class="rowstyle1"><xsl:value-of select="fieldtext"/></td>
<!--td width='20%' bgcolor="{$style1}"><xsl:value-of select="fieldtext"/></td-->
<xsl:for-each select="$r/plan[@plantype = $plantype] ">
<td><xsl:value-of select="field[$p]/fieldvalue" disable-output-escaping="yes"/></td>
</xsl:for-each>
<xsl:for-each select="//plan[generate-id() = generate-id(key('type', @plantype)[1])]">
<td><xsl:value-of select="'N/A'"/></td>
</xsl:for-each>

</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>


I have added a variable plantype, and did some modifications. Check it.
__________________
Rummy
The Following User Says Thank You to mrame For This Useful Post:
kokoness (September 2nd, 2009)
 
Old September 2nd, 2009, 06:55 AM
Authorized User
 
Join Date: Aug 2009
Posts: 31
Thanks: 16
Thanked 1 Time in 1 Post
Default

I think I got it now!

Thanks Rummy! I see the light now. hehehe.

You're awesome!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating xsi:type as an attribute AjayLuthria XSLT 5 May 10th, 2007 09:49 AM
invalid object name 'Groups' marco_27 VB Databases Basics 3 April 16th, 2007 01:59 PM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
Groups Ma7T XSLT 1 August 25th, 2005 12:01 PM
Groups help in 8.5 for VS.net risu Crystal Reports 0 March 15th, 2004 04:27 PM





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