[xsl] Removing Duplicates & Formatting

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

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

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

  <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:value-of select="name()"/>
<xsl:copy-of select="$string"/>


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:




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

Homer Simpson

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

Current Thread