By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,017 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,017 IT Pros & Developers. It's quick & easy.

asp.net/XSl question

P: n/a
I have a xml file and i want to format it using XSL
I needed to do a distinct which is ok on the first node "Code"
But when it gets to the "programDescription" node it prints out values for
both Code="PRG004"
and PRG005 which is CrazyTraining 2 and Program6
I want CrazyTraining 2 for PRG004 and Program6 for PRG005
Any help?
Thx
XSL file
--------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<!--
Get distinct programs into variable
//-->
<xsl:variable name="uniqueCode"
select="//ProgramDetail[not(Code=preceding-sibling::ProgramDetail/Code)]/Cod
e"/>
<xsl:variable name="uniqueProgramDesc"
select="//ProgramDetail[not(programDescription=preceding-sibling::ProgramDet
ail/programDescription)]/programDescription"/>

<xsl:variable name="uniqueCoursecode"
select="//ProgramDetail[not(CourseCode=preceding-sibling::ProgramDetail/Cour
seCode)]/CourseCode"/>
<xsl:variable name="uniqueCourseDesc"
select="//ProgramDetail[not(CourseDescription=preceding-sibling::ProgramDeta
il/CourseDescription)]/CourseDescription"/>
<xsl:variable name="uniqueModuleCode"
select="//ProgramDetail[not(ModuleCode=preceding-sibling::ProgramDetail/Modu
leCode)]/ModuleCode"/>
<xsl:variable name="uniqueModuleDesc"
select="//ProgramDetail[not(uniqueModuleDesc=preceding-sibling::ProgramDetai
l/uniqueModuleDesc)]/ModuleCode"/>


<!--
Reflect to root node and form the HTML page
//-->
<xsl:template match="/">
<html>
<head>
<title>
Programs to be sent
</title>
</head>
<body>
<table border="1">
<tr>
<td><b>Code</b></td>
<td><b>Counts</b></td>
<td><b>Program Description</b></td>
<td><b>Course Code</b></td>
<td><b>Course Description</b></td>
</tr>
<!--
Process specified template
//-->
<xsl:call-template name="processprogramdetail"/>
<xsl:call-template name="processprogramdetail2"/>

<!--
<xsl:call-template name="processprogramdetail3"/>
<xsl:call-template name="processprogramdetail4"/>
<xsl:call-template name="processprogramdetail5"/>

-->
</table>
<table border="1">
<tr>
<td>
<xsl:call-template name="processprogramdetail3"/>
</td>

<td>
<xsl:call-template name="processprogramdetail4"/>
</td>

<td>
<xsl:call-template name="processprogramdetail5"/>
</td>

</tr>
</table>

</body>
</html>
</xsl:template>

<xsl:template name="processprogramdetail">

<!--
Process each distinct Code
//-->
<xsl:for-each select="$uniqueCode">
<!--
Sort by manufacturer
//-->
<xsl:sort select="." />

<!--
Output the Codes into first row
//-->
<tr>
<td><xsl:value-of select="." /></td>
<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>
</tr>

<!--
Gets all program Desc listed
//-->
<xsl:variable name="programDescription"
select="//ProgramDetail[code=current()]/programDescription" />

<tr>
<td><xsl:text>&#xa0;</xsl:text></td>
<!--
Output count of ProgramDescription
//-->
<td valign="top">
<xsl:value-of select="count($programDescription)" /></td>

<td valign="top">
<!--
Process Program Description and print them out
//-->
<xsl:for-each select="$uniqueProgramDesc">
<xsl:sort select="." />
<xsl:value-of select="current()" /><br/>
</xsl:for-each>
</td>


</tr>


<tr>
<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>
<td valign="top">
<!--
Process Program description print them out
//-->
<!--
<xsl:for-each select="$programDescription">
-->
<xsl:for-each select="$uniqueCoursecode">

<xsl:sort select="." />
<xsl:value-of select="current()" />

<br/>

</xsl:for-each>
</td>
</tr>
<tr>
<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>
<td valign="top">
<!--
Process Program description print them out
//-->
<!--
<xsl:for-each select="$programDescription">
-->
<xsl:for-each select="$uniqueCourseDesc">

<xsl:sort select="." />
<xsl:value-of select="current()" />

<br/>

</xsl:for-each>
</td>
</tr>

<xsl:variable name="owners"
select="//ProgramDetail[programDescription=current()]/programDescription" />



</xsl:for-each>

</xsl:template>

<xsl:template name="processprogramdetail2">

<xsl:for-each select="$uniqueCode">

<xsl:sort select="." />


<tr>
<td><xsl:value-of select="." /></td>
<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>
</tr>
<tr>
<td><xsl:text>&#xa0;</xsl:text></td>
<td>
<xsl:for-each select="$uniqueProgramDesc">
<xsl:sort select="." />
<xsl:value-of select="." /><br/>
</xsl:for-each>
</td>

<td><xsl:text>&#xa0;</xsl:text></td>
</tr>



</xsl:for-each>

<!--
<xsl:for-each select="$uniqueCoursecode">
<xsl:sort select="." />
<xsl:value-of select="." /><br/>
</xsl:for-each>
<xsl:for-each select="$uniqueCourseDesc">
<xsl:sort select="." />
<xsl:value-of select="." /><br/>
</xsl:for-each>

<tr>
<td><xsl:text>&#xa0;</xsl:text></td>

<td>

<xsl:for-each select="$uniqueCoursecode">
<xsl:sort select="." />
<xsl:value-of select="." /><br/>
</xsl:for-each>
</td>

<td>

<xsl:for-each select="$uniqueCourseDesc">
<xsl:sort select="." />
<xsl:value-of select="." /><br/>
</xsl:for-each>
</td>

<td><xsl:text>&#xa0;</xsl:text></td>
<td><xsl:text>&#xa0;</xsl:text></td>

</tr>
-->
<!--
Output the Codes into first row
//-->
</xsl:template>
<xsl:template name="processprogramdetail3">
<xsl:for-each select="$uniqueCode">

<xsl:sort select="." />
<xsl:value-of select="." /> <br/>
</xsl:for-each>

</xsl:template>

<xsl:template name="processprogramdetail4">
<xsl:for-each select="$uniqueProgramDesc">

<xsl:sort select="." />
<xsl:value-of select="." /><br/>
</xsl:for-each>

</xsl:template>
<xsl:template name="processprogramdetail5">
<xsl:for-each select="$uniqueCourseDesc">

<xsl:sort select="." />
<xsl:value-of select="." /><br/>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>
XML file
--------------
<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="testemail.xsl"?>
<NewDataSet>
<ProgramDetail>
<Code>PRG004</Code>
<programDescription>Crazy Training 2</programDescription>
<CourseCode>MAT01</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths For Beginners</CourseDescription>
<ModuleCode>TEST101</ModuleCode>
<ModuleDescription>Test Module</ModuleDescription>
</ProgramDetail>
<ProgramDetail>
<Code>PRG004</Code>
<programDescription>Crazy Training 2</programDescription>
<CourseCode>PHS101</CourseCode>
<DurationHours>36</DurationHours>
<CourseDescription>Physics</CourseDescription>
<ModuleCode>TEST101</ModuleCode>
<ModuleDescription>Test Module</ModuleDescription>
<PreReqCourseCode>MAT234</PreReqCourseCode>
</ProgramDetail>
<ProgramDetail>
<Code>PRG004</Code>
<programDescription>Crazy Training 2</programDescription>
<CourseCode>PHS101</CourseCode>
<DurationHours>36</DurationHours>
<CourseDescription>Physics</CourseDescription>
<ModuleCode>TEST103</ModuleCode>
<ModuleDescription>TESTMODULEWITHLONGNAME</ModuleDescription>
<PreReqCourseCode>MAT234</PreReqCourseCode>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>COURSE102</CourseCode>
<DurationHours>5</DurationHours>
<CourseDescription>Course for learning Courses</CourseDescription>
<ModuleCode>MODULE101</ModuleCode>
<ModuleDescription>Module 1</ModuleDescription>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>MAT01</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths For Beginners</CourseDescription>
<ModuleCode>TEST101</ModuleCode>
<ModuleDescription>Test Module</ModuleDescription>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>MAT234</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths</CourseDescription>
<ModuleCode>TEST101</ModuleCode>
<ModuleDescription>Test Module</ModuleDescription>
<PreReqCourseCode>MAT01</PreReqCourseCode>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>MAT234</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths</CourseDescription>
<ModuleCode>TEST101</ModuleCode>
<ModuleDescription>Test Module</ModuleDescription>
<PreReqCourseCode>MAT101</PreReqCourseCode>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>MAT234</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths</CourseDescription>
<ModuleCode>TEST101</ModuleCode>
<ModuleDescription>Test Module</ModuleDescription>
<PreReqCourseCode>PHS101</PreReqCourseCode>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>MAT234</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths</CourseDescription>
<ModuleCode>TEST102</ModuleCode>
<ModuleDescription>TestModule2</ModuleDescription>
<PreReqCourseCode>MAT01</PreReqCourseCode>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>MAT234</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths</CourseDescription>
<ModuleCode>TEST102</ModuleCode>
<ModuleDescription>TestModule2</ModuleDescription>
<PreReqCourseCode>MAT101</PreReqCourseCode>
</ProgramDetail>
<ProgramDetail>
<Code>PRG005</Code>
<programDescription>Program 6</programDescription>
<CourseCode>MAT234</CourseCode>
<DurationHours>8</DurationHours>
<CourseDescription>Maths</CourseDescription>
<ModuleCode>TEST102</ModuleCode>
<ModuleDescription>TestModule2</ModuleDescription>
<PreReqCourseCode>PHS101</PreReqCourseCode>
</ProgramDetail>
</NewDataSet>
Feb 23 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.