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

RE: listing unique attributes

Subject: RE: listing unique attributes
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Tue, 14 Jan 2003 16:46:52 -0000
xsl unique attribute
Hi Zack.

This is a group problem. You want to group by section and by @who.
These templates gives the result you want.

 <!-- this key gets all quotes grouped by section and @who -->
 <xsl:key name="quotes" match="quote"
use="concat(generate-id(ancestor::section),'-',@who)"/>
 
 <xsl:template match="section">
  <span>Section <xsl:value-of select="position()"/></span><br/><!-- just
displaying the current section -->
 
<xsl:text>--------------------------------------------------------------
------</xsl:text><br/>
  <xsl:apply-templates
select=".//quote[generate-id()=generate-id(key('quotes',concat(generate-
id(ancestor::section),'-',@who)))]"/><!-- this will get the diferent
quotes of this section -->
  <br/>
 
<xsl:text>--------------------------------------------------------------
------</xsl:text><br/>
 </xsl:template>
 
 <xsl:template match="quote">
 <xsl:if test="position()&gt;1">
 <xsl:text>,&#160;</xsl:text>
 </xsl:if>
 <a href="quotes/{@who}.html"><xsl:value-of select="@who"/></a>
 </xsl:template>

Hope this helps you.

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Zack Brown
Sent: terça-feira, 14 de Janeiro de 2003 13:54
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  listing unique attributes


Hi folks,

I'm having a problem creating a list of items from a set of items within
a given tag. I have a file that looks like this:

--------------------------------------------------------------------
<?xml version="1.0" ?>
<kc>
<section>

<p>some text <quote who="person A">more text</quote> more text <quote
who="person B">more text</quote> and more.</p>

<quote who="person A">
<p>text</p>
</quote>

<p>text <quote who="person B">more text</quote></p>

<p>

<ul>

<li>text <quote who="person C">text</quote></li>

</ul>

</p>

</section>

<section>
<quote who="person C"></quote>
</section>

</kc>
--------------------------------------------------------------------

in other words, within a <section> tag, there may be <quote> tags by
themselves, or <quote> tags nested within other tags. The "who"
attribute of a quote tag is a person's name. "who" attributes may repeat
in a given section.

I have an xslt recipe that looks like this:

--------------------------------------------------------------------
<xsl:template match="kc/section" mode="full">
<xsl:if test=".//quote">
Quoted:
    <xsl:for-each
select=".//@who[not(following-sibling::quote/@who=.)]">
<a href="quotes/{.}.html"><xsl:value-of select="."/></a>
        <xsl:if test="not(position() = last())">,&#160;</xsl:if>
    </xsl:for-each>
</xsl:if>
</xsl:template>
--------------------------------------------------------------------

What I would like is for this recipe to produce the following output
when applied to the first <section> in the file above:

--------------------------------------------------------------------
<a href="quotes/person A.html">person A</a>,&#160;<a href="quotes/person
B.html">person B</a>,&#160;<a href="quotes/person C.html">person C</a>
--------------------------------------------------------------------

and when applied to the second <section> in the file above:

--------------------------------------------------------------------
<a href="quotes/person C.html">person C</a>
--------------------------------------------------------------------

In other words, each person should only be listed once for a given
section, no matter how many times they appear in that section.

But I can't seem to make it go somehow. Could someone please give me a
hand?

Many thanks,
Zack

-- 
Zack Brown

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


 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.