Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grouping with XSLT

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
0
0
US
Hi all,

I've been trying all day to do some groupings from an xml doc.

The XML I have looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<dataroot>
		<List>
			<ID>66</ID>
			<Title>Title1</Title>
			<Mapping>Yes</Mapping>
			<Link>L1</Link>
		</List>
		<List>
			<ID>67</ID>
			<Title>Title2</Title>
<Mapping>Yes</Mapping>
			<Link>L2</Link>
		</List>
		<List>
			<ID>68</ID>
			<Title>Title3</Title>
<Mapping>None</Mapping>
			<Link>L3</Link>
		</List>
		<List>
			<ID>69</ID>
			<Title>Title4</Title>
<Mapping>None</Mapping>
			<Link>L4</Link>
		</List>
		<List>
			<ID>70</ID>
			<Title>Title5</Title>
			<Mapping>Yes</Mapping>
			<Link>L5</Link>
		</List>
</dataroot>
and the XSLT:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
	<xsl:output method="html" indent="yes"/>
	<xsl:param name="courseTitle" select="test"/>
	<xsl:param name="examMapping" select="70-236"/>
	<xsl:template match="/">
			
				<xsl:call-template name="core"/>
	</xsl:template>
  
	<xsl:template match="List" name="core">
				<table class="borders" border="0" width="100%" cellpadding="2" cellspacing="0" bgcolor="#efefef">
					<tr valign="top">
						<td colspan="1" class="largeWhiteText" bgcolor="#F87311">
						&#xa0;
						</td>
						<td colspan="1" class="largeWhiteText" bgcolor="#F87311">
							<span>
								Title
							</span>
						</td>
						<td colspan="1" class="largeWhiteText" bgcolor="#F87311">
							<span>
								Link
							</span>
						</td>
					</tr>[COLOR=red]
					<xsl:for-each select="/dataroot/List[Mapping='Yes']">
						<tr>
							<td colspan="1">
								<b/>
							</td>
							<td colspan="1">
								<xsl:value-of select="/dataroot/List[Title=$courseTitle]/Title"/>
							</td>
							<td colspan="1">
								<xsl:value-of select="/dataroot/List[Title='$courseTitle]/Link"/>
							</td>
						</tr>
					</xsl:for-each>[/color]
				</table>
		<p/>
	</xsl:template>
  
</xsl:stylesheet>

What I would like to output is something like:

Title1 L1
Title2 L2
Title5 L3

Could someone help me figure out how to do this? Thank you in advance!!!!
 
There are many problems.

[1] You need to "quot" the parameter setting to string.
[tt] <xsl:param name="courseTitle" select="[red]'[/red]test[red]'[/red]"/>
<xsl:param name="examMapping" select="[red]'[/red]70-236[red]'[/red]"/>[/tt]

[2] The matching schema should be re-think. (see revision)

[3] You sample document has no Title "test", so in order to produce what you anticipate, I would say the conditional "=$courseTitle" should be understood as its inverse "not equal to"!? In any case, the way to put data into the td with a further condition on List should be rewritten. (see revision)
[tt]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:eek:utput method="html" indent="yes"/>
<xsl:param name="courseTitle" select="[red]'[/red]test[red]'[/red]"/>
<xsl:param name="examMapping" select="[red]'[/red]70-236[red]'[/red]"/>
<xsl:template match="/">

<xsl:call-template name="core"/>
</xsl:template>

<xsl:template match="[red]dataroot[/red]" name="core">
<table class="borders" border="0" width="100%" cellpadding="2" cellspacing="0" bgcolor="#efefef">
<tr valign="top">
<td colspan="1" class="largeWhiteText" bgcolor="#F87311">
&#xa0;
</td>
<td colspan="1" class="largeWhiteText" bgcolor="#F87311">
<span>
Title
</span>
</td>
<td colspan="1" class="largeWhiteText" bgcolor="#F87311">
<span>
Link
</span>
</td>
</tr>
<xsl:for-each select="[red].//[/red]List[Mapping='Yes']">
<tr>
<td colspan="1">
<b/>
</td>
<td colspan="1">
[red]<xsl:choose>
<xsl:when test="Title [red]!=[/red] $courseTitle">
<xsl:value-of select="Title"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="'&#xa0;'" />
</xsl:eek:therwise>
</xsl:choose>[/red]
</td>
<td colspan="1">
[red]<xsl:choose>
<xsl:when test="Title [red]!=[/red] $courseTitle">
<xsl:value-of select="Link"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="'&#xa0;'" />
</xsl:eek:therwise>
</xsl:choose>[/red]
</td>
</tr>
</xsl:for-each>
</table>
<p/>
</xsl:template>

</xsl:stylesheet>
[/tt]
This should be closer to what needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top