XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Posttop
wayne posnerSubject: Newbie: Help with counting and removing duplicate elements
Author: wayne posner
Date: 28 Feb 2007 04:55 PM
Hi all.

I'm a definite newbie when it comes to XSLT. I've got an XSL file that takes an XML of one schema and maps it to another. As a result of the mapping I end up with duplicate sibling nodes in my tree. I need to remove the duplicates but count how many there were and set that value to a qty attribute in the remaining node. It is possible that there would be other nodes of the same value elsewhere in the tree, but I'm only concerned when they're immediate siblings.

I've done searches and read up on grouping and counting using the Muenchian Method, but I'm not sure how to modify my existing XSL to include the code and even just trying to do a simple count in a completely new XSL has been resulting in nothing being returned. Below is my current XSL code...any help would be greatly appreciated!

<?xml version='1.0' ?>
<xsl:stylesheet version="2.0" xmlns:pc_function="uri://none" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:a="righthemisphere.deepserver.bom">


<msxsl:script language="JavaScript" implements-prefix="pc_function">
<![CDATA[
function rand()
{
return "" + Math.random()*100000;
}
]]>
</msxsl:script>

<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>

<xsl:template match="/">
<catalog>
<xsl:attribute name="name">
<xsl:value-of select="a:assembly/@name"/>
</xsl:attribute>

<item>
<xsl:attribute name="uid">
<xsl:value-of select="substring-after(pc_function:rand(),'.')"/>
</xsl:attribute>

<name>
<xsl:value-of select="translate(a:assembly/@name,$ucletters,$lcletters)"/>
</name>

<xsl:element name="number"/>
<xsl:element name="description"/>
<xsl:element name="qty"/>
<xsl:element name="uom"/>
<xsl:element name="unit_cost"/>
<xsl:element name="hasChild"/>

<xsl:apply-templates select="a:assembly/a:instance"/>
</item>
</catalog>
</xsl:template>

<xsl:template match="a:instance">
<item>
<xsl:attribute name="uid">
<xsl:value-of select="substring-after(pc_function:rand(),'.')"/>
</xsl:attribute>

<name>
<xsl:value-of select="translate(@name,$ucletters,$lcletters)"/>
</name>

<xsl:element name="number"/>
<xsl:element name="description"/>
<xsl:element name="qty"/>
<xsl:element name="uom"/>
<xsl:element name="unit_cost"/>
<xsl:element name="hasChild"/>
<xsl:apply-templates select="a:instance"/>
</item>
</xsl:template>
</xsl:stylesheet>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.