Altova Mailing List Archives


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

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 7/23/2003 2:06:00 PM
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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.