Results 1 to 2 of 2

Thread: newbie - problem with creating xslt style sheet to transform xml to xhtml

  1. #1
    Join Date
    Oct 2009

    Angry newbie - problem with creating xslt style sheet to transform xml to xhtml


    I want to create a xslt 1.0 style sheet (my code so far see below) to transform an .xml (code see below)to an xhtml document that that uses a .css file (code see below) for final presentation in a web browser.

    The .css and the .xml are not to be modified in any way.

    As you can see, I managed to get the majority of the text to display – even the “stagedir” between the “Speech” instances displays, but where I hit a wall is the display of the “stagedir” when it comes up within the “Speech”.

    As you can see, there are two locations of the stagedir, one where it is within a line (i highlighted it in blue) and which is "Problem 1", and "Problem 2", where the stagedir sits between the lines (I highlighted it in red in the example above).

    xml code:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="xhtml.xsl"?>
    	<TITLE>The Tragedy of Macbeth</TITLE>
    			<GROUP DESCRIPTION="Generals">
    			<GROUP DESCRIPTION="Noblemen">
    			<GROUP DESCRIPTION="Witches">
    	<TITLE>SCENE III.  A heath near Forres.</TITLE>
    	<STAGEDIR>Thunder. Enter the three Witches</STAGEDIR>
    <SPEAKER description="Witches">FIRST WITCH</SPEAKER>
    <LINE>Where hast thou been, sister?</LINE>
    <LINE>Killing swine.</LINE>
    <SPEAKER person="witch">THIRD WITCH</SPEAKER>
    <LINE>Sister, where thou?</LINE>
    	<STAGEDIR>Drum within</STAGEDIR>
    <SPEAKER person="witch">THIRD WITCH</SPEAKER>
    <LINE>A drum, a drum!</LINE>
    <LINE>Macbeth doth come.</LINE>
    <SPEAKER person="all">ALL</SPEAKER>
    <LINE>The weird sisters, hand in hand,</LINE>
    <LINE>Posters of the sea and land,</LINE>
    <LINE>Thus do go about, about:</LINE>
    <LINE>Thrice to thine and thrice to mine</LINE>
    <LINE>And thrice again, to make up nine.</LINE>
    <LINE>Peace! the charm's wound up.</LINE>
    <SPEAKER person="generals">MACBETH</SPEAKER>
    <LINE>So foul and fair a day I have not seen.</LINE>
    <SPEAKER person="witch">THIRD WITCH</SPEAKER>
    <LINE>All hail, Macbeth, thou shalt be king hereafter!</LINE>
    <SPEAKER person="witch">FIRST WITCH</SPEAKER>
    <SPEAKER person="generals">MACBETH</SPEAKER>
    <LINE>Stay, you imperfect speakers, tell me more:</LINE>
    <LINE>By Sinel's death I know I am thane of Glamis;</LINE>
    <LINE>But how of Cawdor? the thane of Cawdor lives,</LINE>
    <LINE>A prosperous gentleman; and to be king</LINE>
    <LINE>Stands not within the prospect of belief,</LINE>
    <LINE>No more than to be Cawdor. Say from whence</LINE>
    <LINE>You owe this strange intelligence? or why</LINE>
    <LINE>Upon this blasted heath you stop our way</LINE>
    <LINE>With such prophetic greeting? Speak, I charge you.</LINE>
    <SPEAKER person="generals">BANQUO</SPEAKER>
    <LINE>The earth hath bubbles, as the water has,</LINE>
    <LINE>And these are of them. Whither are they vanish'd?</LINE>
    <SPEAKER person="noblemen">ANGUS</SPEAKER>
    <LINE>We are sent</LINE>
    <LINE>To give thee from our royal master thanks;</LINE>
    <LINE>Only to herald thee into his sight,</LINE>
    <LINE>Not pay thee.</LINE>
    <SPEAKER person="generals">BANQUO</SPEAKER>
    <LINE>What, can the devil speak true?</LINE>
    <SPEAKER person="generals">MACBETH</SPEAKER>
    		<LINE><STAGEDIR>Aside</STAGEDIR>  Glamis, and thane of Cawdor!</LINE><LINE>The greatest is behind.</LINE>
    	<STAGEDIR>To ROSS and ANGUS</STAGEDIR><LINE>Thanks for your pains.</LINE>
    	<STAGEDIR>To BANQUO</STAGEDIR><LINE>Do you not hope your children shall be kings,</LINE>
    <LINE>When those that gave the thane of Cawdor to me</LINE>
    <LINE>Promised no less to them?</LINE>
    <SPEAKER person="generals">MACBETH</SPEAKER>
    		<LINE><STAGEDIR>Aside</STAGEDIR> Two truths are told,</LINE>
    <LINE>As happy prologues to the swelling act</LINE>
    <LINE>Of the imperial theme.--I thank you, gentlemen.</LINE>
    		<LINE><STAGEDIR>Aside</STAGEDIR>  This supernatural soliciting</LINE>
    <LINE>Cannot be ill, cannot be good: if ill,</LINE>
    <LINE>Why hath it given me earnest of success,</LINE>
    <LINE>Commencing in a truth? I am thane of Cawdor:</LINE>
    <LINE>If good, why do I yield to that suggestion</LINE>
    <LINE>Whose horrid image doth unfix my hair</LINE>
    <LINE>And make my seated heart knock at my ribs,</LINE>
    <LINE>Against the use of nature? Present fears</LINE>
    <LINE>Are less than horrible imaginings:</LINE>
    <LINE>My thought, whose murder yet is but fantastical,</LINE>
    <LINE>Shakes so my single state of man that function</LINE>
    <LINE>Is smother'd in surmise, and nothing is</LINE>
    <LINE>But what is not.</LINE>
    <SPEAKER person="generals">MACBETH</SPEAKER>
    		<LINE><STAGEDIR>Aside</STAGEDIR>  If chance will have me king, why, chance may crown me,</LINE>
    <LINE>Without my stir.</LINE>
    <SPEAKER person="generals">MACBETH</SPEAKER>	
    		<LINE><STAGEDIR>Aside</STAGEDIR>Come what come may,</LINE>
    <LINE>Time and the hour runs through the roughest day.</LINE>
    <SPEAKER person="generals">BANQUO</SPEAKER>
    <LINE>Worthy Macbeth, we stay upon your leisure.</LINE>
    <SPEAKER person="generals">MACBETH</SPEAKER>
    <LINE>Till then, enough. Come, friends.</LINE>
    css code:

    body {font-family: Arial, sans-serif; color: #000000;}
    h1, h2, h3, h4 {font-family: "Comic Sans MS", cursive; }
    h3,h4 {font-weight: normal;}
    dt {font-weight: bold; }
    dd {font-family: "Times New Roman", serif; font-size: 1.2em; font-style: italic;}
    hr {color: #000000;}
    .act {background-color: #CCCFFF; margin:10px; padding: 10px; width: 75%;}
    .Generals {background-color: #CC99FF; padding-left: 5px;}
    .Noblemen {background-color: #FFFFFF; padding-left: 5px;}
    .Witches {background-color: #99FFCC; padding-left: 5px;}
    .All {background-color: #FF0000; padding-left: 5px;}
    .stagedirection {font-size: 0.85em; font-weight: bold; padding-left: 5px;}
    My xslt code so far:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" encoding="ISO-8859-1" version="1.0" 
        omit-xml-declaration="yes" media-type="text/html" indent="yes" />
      <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
          <title>An XSLT style sheet for Macbeth</title>
          <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
          <link rel="stylesheet" type="text/css" href="macbeth.css"/>
    	<h1><xsl:value-of select="PLAY/TITLE" /></h1>
    	<h2><xsl:value-of select="PLAY/ACT/TITLE" /></h2>
    	<div class="act">
    	<h3><xsl:value-of select="PLAY/ACT/SCENE/TITLE" /></h3>
    	<hr />
    	<xsl:for-each select="PLAY/ACT/CHARACTERS/GROUP">
    		  <xsl:when test="@DESCRIPTION='Generals'">
    			<xsl:attribute name="class">Generals</xsl:attribute>
    		  <xsl:when test="@DESCRIPTION='Noblemen'">
    			<xsl:attribute name="class">Noblemen</xsl:attribute>
    		  <xsl:when test="@DESCRIPTION='Witches'">
    			<xsl:attribute name="class">Witches</xsl:attribute>
    		<h4><xsl:value-of select="@DESCRIPTION" /></h4>
    		<p><xsl:apply-templates select="PERSON"/></p>
    	<hr />
    	<xsl:for-each select="PLAY/ACT/SCENE">
    	<xsl:apply-templates select="STAGEDIR|SPEECH"/>
    	<xsl:template match="PERSON">
       	<xsl:value-of select="."/><br />
      	<xsl:template match="STAGEDIR">
    	<xsl:attribute name="class">stagedirection</xsl:attribute>
    	<p>[<xsl:value-of select="." />]</p>
    	<xsl:template match="SPEECH">
    		  <xsl:when test="SPEAKER='FIRST WITCH'">
    			<xsl:attribute name="class">Witches</xsl:attribute>
    		  <xsl:when test="SPEAKER='SECOND WITCH'">
    			<xsl:attribute name="class">Witches</xsl:attribute>
    		  <xsl:when test="SPEAKER='THIRD WITCH'">
    			<xsl:attribute name="class">Witches</xsl:attribute>
    		  <xsl:when test="SPEAKER='ALL'">
    			<xsl:attribute name="class">All</xsl:attribute>
    		  <xsl:when test="SPEAKER='MACBETH'">
    			<xsl:attribute name="class">Generals</xsl:attribute>
    		  <xsl:when test="SPEAKER='BANQUO'">
    			<xsl:attribute name="class">Generals</xsl:attribute>
    		  <xsl:when test="SPEAKER='ROSS'">
    			<xsl:attribute name="class">Noblemen</xsl:attribute>
    		  <xsl:when test="SPEAKER='ANGUS'">
    			<xsl:attribute name="class">Noblemen</xsl:attribute>
    		 <p><xsl:value-of select="SPEAKER" /></p>
    		<xsl:apply-templates select="LINE"/>
    <xsl:template match="LINE">
    <dd><xsl:value-of select="."/></dd>
    Any help would be really appreciated.

  2. #2
    Join Date
    Jul 2008
    urbana, il
    not sure 100&#37; what you need.
    some more specific selectors to play with:

    <xsl:template match="//STAGEDIR"> any stagedir
    <xsl:template match="//LINE/STAGEDIR"> in-line stagedirs
    <xsl:template match="//SPEECH/STAGEDIR"> non in-line stagedirs...
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.08990 seconds
  • Memory Usage 2,875KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates