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

Re: How to show distinct node values?

Subject: Re: How to show distinct node values?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 23 Jul 2003 18:04:24 -0400
xsl for each distinct
At 2003-07-23 16:44 +0200, Poort, J. wrote:
I'm using a big XML file and want to transform the data by XSL
I open the XML in IE 6.0 and say  href="r_and_j.xslt".
In r_and_j.xslt  I enter the XSL-commands.

The XML file contains the play Romeo and Juliet.
I want now to show in a table for each ACT and each SCENE the names of the SPEAKER
and the number of LINES he has to speak.
Problemn is that I'm not able to show the distinct node values for the SPEAKER.

Because you want this scoped within each scene, this can be easily and succinctly done with variables in about 15 instructions and handle all of the scenes in all of the acts. I tested this in IE6 successfully for your one act.


I hope the answer below helps.

................. Ken


T:\xsllist>type r_and_j.xslt <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="html"/>

<xsl:template match="/">
<pre>
  <xsl:for-each select="/PLAY/ACT">
    <xsl:text/>ACT <xsl:number format="I"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:for-each select="SCENE">
      <xsl:text>&#x9;</xsl:text>
      <xsl:text/>SCENE <xsl:number format="I"/><xsl:text>&#xa;</xsl:text>
      <xsl:variable name="speeches" select=".//SPEECH"/>
      <xsl:for-each select="$speeches">
        <xsl:if test="generate-id(.)=
                      generate-id($speeches[SPEAKER=current()/SPEAKER])">
          <xsl:text>&#x9;&#x9;</xsl:text>
          <xsl:value-of select="SPEAKER"/>
          <xsl:text>&#x9;</xsl:text>
          <xsl:value-of select="count($speeches[SPEAKER=current()/SPEAKER]
                                /LINE)"/>
          <xsl:text>&#xa;</xsl:text>
        </xsl:if>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:for-each>
</pre>
</xsl:template>

</xsl:stylesheet>

T:\xsllist>type poort.xml
<?xml version="1.0" standalone="yes"?><?xml-stylesheet type="text/xsl" href="r_and_j.xslt"?>


<PLAY>
<TITLE>The Tragedy of Romeo and Juliet</TITLE>
<PLAYSUBT>ROMEO AND JULIET</PLAYSUBT>
<ACT><TITLE>ACT I</TITLE>
<SCENE><TITLE>SCENE I.  Verona. A public place.</TITLE>
<STAGEDIR>Enter SAMPSON and GREGORY, of the house of Capulet,
armed with swords and bucklers</STAGEDIR>
<SPEECH>
<SPEAKER>SAMPSON</SPEAKER>
<LINE>Gregory, o' my word, we'll not carry coals.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>GREGORY</SPEAKER>
<LINE>No, for then we should be colliers.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>SAMPSON</SPEAKER>
<LINE>I mean, an we be in choler, we'll draw.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>GREGORY</SPEAKER>
<LINE>Ay, while you live, draw your neck out o' the collar.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>SAMPSON</SPEAKER>
<LINE>'Tis all one, I will show myself a tyrant: when I</LINE>
<LINE>have fought with the men, I will be cruel with the</LINE>
<LINE>maids, and cut off their heads.</LINE>
</SPEECH>

<STAGEDIR>Enter ABRAHAM and BALTHASAR</STAGEDIR>

<SPEECH>
<SPEAKER>ABRAHAM</SPEAKER>
<LINE>Do you bite your thumb at us, sir?</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>SAMPSON</SPEAKER>
<LINE>I do bite my thumb, sir.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BENVOLIO</SPEAKER>
<LINE>Part, fools!</LINE>
<LINE>Put up your swords; you know not what you do.</LINE>
</SPEECH>
<STAGEDIR>Beats down their swords</STAGEDIR>
<STAGEDIR>Enter TYBALT</STAGEDIR>

<SPEECH>
<SPEAKER>TYBALT</SPEAKER>
<LINE>What, art thou drawn among these heartless hinds?</LINE>
<LINE>Turn thee, Benvolio, look upon thy death.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BENVOLIO</SPEAKER>
<LINE>I do but keep the peace: put up thy sword,</LINE>
<LINE>Or manage it to part these men with me.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>TYBALT</SPEAKER>
<LINE>What, drawn, and talk of peace! I hate the word,</LINE>
<LINE>As I hate hell, all Montagues, and thee:</LINE>
<LINE>Have at thee, coward!</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>PRINCE</SPEAKER>
<LINE>Rebellious subjects, enemies to peace,</LINE>
<LINE>Profaners of this neighbour-stained steel,--</LINE>
<LINE>Will they not hear? What, ho! you men, you beasts,</LINE>
<LINE>That quench the fire of your pernicious rage</LINE>
<LINE>With purple fountains issuing from your veins,</LINE>
<LINE>On pain of torture, from those bloody hands</LINE>
<LINE>Throw your mistemper'd weapons to the ground,</LINE>
<LINE>And hear the sentence of your moved prince.</LINE>
<LINE>Three civil brawls, bred of an airy word,</LINE>
<LINE>By thee, old Capulet, and Montague,</LINE>
<LINE>Have thrice disturb'd the quiet of our streets,</LINE>
<LINE>And made Verona's ancient citizens</LINE>
<LINE>Cast by their grave beseeming ornaments,</LINE>
<LINE>To wield old partisans, in hands as old,</LINE>
<LINE>Canker'd with peace, to part your canker'd hate:</LINE>
<LINE>If ever you disturb our streets again,</LINE>
</SPEECH>
</SCENE>
</ACT>

</PLAY>

T:\xsllist>saxon poort.xml r_and_j.xslt
<pre>ACT I
        SCENE I
                SAMPSON 6
                GREGORY 2
                ABRAHAM 1
                BENVOLIO        4
                TYBALT  5
                PRINCE  16
</pre>
T:\xsllist>rem Done!


-- Upcoming hands-on courses: in-house corporate training available; North America public: XSL-FO Aug 4,2003; XSLT/XPath Aug 12, 2003

G. Ken Holman                mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X              Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:    http://XMLGuild.info
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc


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.