Re: [xsl] How to show distinct node values?

Subject: Re: [xsl] How to show distinct node values?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 23 Jul 2003 18:04:24 -0400
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=""; version="1.0">

<xsl:output method="html"/>

<xsl:template match="/">
  <xsl:for-each select="/PLAY/ACT">
    <xsl:text/>ACT <xsl:number format="I"/>
    <xsl:for-each select="SCENE">
      <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(.)=
          <xsl:value-of select="SPEAKER"/>
          <xsl:value-of select="count($speeches[SPEAKER=current()/SPEAKER]


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

<TITLE>The Tragedy of Romeo and Juliet</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>
<LINE>Gregory, o' my word, we'll not carry coals.</LINE>
<LINE>No, for then we should be colliers.</LINE>
<LINE>I mean, an we be in choler, we'll draw.</LINE>
<LINE>Ay, while you live, draw your neck out o' the collar.</LINE>

<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>


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

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

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

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

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

<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>

<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>


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
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.
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:
Male Breast Cancer Awareness

XSL-List info and archive:

Current Thread