|
-
Dec 2nd, 2006, 11:32 AM
#1
Thread Starter
New Member
Removing duplications from XML using XSL styelsheets.
Hello im basically creating a form based system using drop down menu's where as I have an XML document, then am processing that using an XSL (HTML ORITENTATED) document, sending them both to a JSP and processing them to output xhtml.
My problem is that in the form drop down menu from the XML I extract many peices of information which are the same. For instance say im making a list of the courses, but the 'Computer science' course is listed 3 times I want to only list that course in the menu once. I've got around this problem using a predicate as follows.
Code:
<xsl:apply-templates select="curriculum/modules/module/subject[not(.=preceding::subject/.)]" mode="q2d" />
The problem in facing now is that im only extracting part of the XML from a document, for instance module codes like CSCI1401, CSCI1408, INFO2403. I only want to retreive the first 4 letters of these module codes, so to do this im using substring(.,1,4) however I can get rid of duplicates in the way that I dont have two CSCI1401's but I can't seem to get the drop down menu to just contain 1 instance of CSCI, INFO, etc.
Any ideas on how you remove duplicates when you're trying to remove them based on a substring? It won't let me put the substring function directly into the tree structure because it requires a node ;s
-
Dec 10th, 2006, 03:18 PM
#2
Re: Removing duplications from XML using XSL styelsheets.
Are you using any front-end language which you could possibly combine the xsl transformation with?
-
Dec 10th, 2006, 03:59 PM
#3
Thread Starter
New Member
Re: Removing duplications from XML using XSL styelsheets.
No we're not aloud to, we have to use just XSL, XML and JSP to output XHTML. Anyway I have kinda got round the problem to some extent, using an apply template as follows.
Code:
<xsl:apply-templates select="curriculum/modules/module[not(substring(@code,1,4)=substring(following-sibling::module/@code,1,4))]" mode="q3fa"/>
This works but still leaves 2 duplicates, i.e. 2 instances of CSCI and 2 of INFO in the drop down menu. I've found the reasoning for this is because theres level 1 and level 2 modules, and the CSCI's are listed in level 1, then start again in the level 2 module list, unfortunately I can't change the ordering of the XML either.
The way I see it the only way around it is using a sort method, ive tried something like follows:
Code:
<xsl:apply-templates select="curriculum/modules/module[not(substring(@code,1,4)=substring(following-sibling::module/@code,1,4))]" mode="q3fa">
<xsl:sort select="@code"/>
</xsl:apply-templates>
but it only orders the dropdown menu after the informations been extracted and so I want someway of ordering all the module/@code's then using that sorted list in my apply templates predicate. Anyone know how to do this? Trouble it don't seem to let you use variables straight into apply templates.
-
Dec 10th, 2006, 05:12 PM
#4
Re: Removing duplications from XML using XSL styelsheets.
Use a for-each to order them and an if to filter them after the fact.
Something like
Code:
<xsl:for-each select="unfiltered expression">
<xsl:sort by the value/>
<xsl:if test="filter expression">
<!-- real stuff here -->
</xsl:if>
</xsl:for-each>
Or use a different axis instead of preceding-sibling, perhaps preceding. That might work.
Last edited by CornedBee; Dec 10th, 2006 at 05:16 PM.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 10th, 2006, 06:53 PM
#5
Thread Starter
New Member
Re: Removing duplications from XML using XSL styelsheets.
I tried doing this:
Code:
<xsl:for-each select="curriculum/modules/module">
<xsl:sort select="@code" order="ascending" />
<xsl:if test="self::node()[not(substring(@code,1,4)=substring(following-sibling::module/@code,1,4))]">
<xsl:apply-templates select="." mode="q3fa" />
</xsl:if>
</xsl:for-each>
But it still gives me the same duplicates? doesn't seem to be ordering them how I want them too.. or ordering the XML before it applies the template?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|