[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Removing Duplicates & Formatting

Subject: Removing Duplicates & Formatting
From: JCS <subscriber@xxxxxxxxxxxxx>
Date: Wed, 10 Dec 2003 20:12:48 +1300
xsl removing duplicates
Hi all,

I've created the stylesheet that gives me an element stack from an XML file
(thanks David):

<xsl:template match="/">
<html>
    <font face="'Courier New', Courier, mono">
      <xsl:for-each select="//*[not(*)]">
        <xsl:call-template name="path"/><br/>
      </xsl:for-each>
    </font>
</html>
  </xsl:template>

  <xsl:template name="path">
    <!--this is selecting the ancestors of current node-->
    <xsl:variable name="string">
    <xsl:for-each select="ancestor::*">
             <xsl:value-of select="name()"/>
      
      <xsl:text>/</xsl:text>
    </xsl:for-each>
    
      <xsl:value-of select="name()"/>
    
    </xsl:variable>
<xsl:copy-of select="$string"/>
  </xsl:template>

</xsl:stylesheet>


You'll notice I've put the path selection in a variable "string". I was
playing around with variables because I want to be able to remove the
duplicate paths created from this stylesheet. For example:


 foo/bar
 foo/bar
 foo/foo/bar/chocolate/crunch
 foo/foo/bar/chocolate/crunch
 foo/bar/manchu

Becomes

 foo/bar
 foo/foo/bar/chocolate/crunch
 foo/bar/manchu


I've looked in the FAQ but I'm afraid I don't know how to apply the samples
to my situation. Because I'm "building" a string I thought I would have to
match duplicates in a key perhaps? But then you can't match a variable with
a key (i.e. Key match=$string is invalid, right?)

There's another aspect of this as well, which is that I *also* want to be
able to format the element stack path, so that the last element is in red
and the ancestors are in blue, for example. I've done this easily (that's
why the the $string value is printed using copy-of instead of value-of,
because I used to have HTML in there as well.) But I imagine I'll have to
make "two passes" or perhaps use two modes, one to remove the duplicates and
the other to format it? This is the part in XSL where the concept seems easy
enough, but the execution may be tricky.

Any pointers in the right direction would be appreciated, at the very least
the most important thing is to get the duplicates removed.

/johnny :)

-- 
"I'm not normally a praying man, but if you're up there please save me
Superman!" 

Homer Simpson


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.