Closed kes213 closed 6 years ago
Wait, I think I figured it out, but someone can still take a look if they want, just in case.
I was missing the <xsl:mode on-no-match="shallow-copy"/>
at the beginning of my XSLT document.
@kes213 I was just taking a look at your code, and I needed to see a sample input XML, so I was looking at https://github.com/kes213/Harlem_Ren_Project/blob/master/Poem%20XML%20Documents/McKay/McKay_After_the_Winter.xml
I'm a little confused by your solution: I don't know why you'd want to do an identity transformation. (That is what xsl:mode on-no-match="shallow-copy"/>
is for.) You probably want to be setting your <xsl:output>
to html
, since this is an XML to HTML transformation (and you should model that on earlier homework assignments, using the xsl:output line we provide.)
If you're using shallow-copy, you're probably outputting your <punc>
XML elements in your HTML, and that's going to produce non-valid HTML. Instead, our goal here is to transform those XML elements into legal HTML elements: You want to transform <punc type="Something">
to <span class="Something">
. So you just need to write an <xsl:template>
rule to handle your <punc>
elements and convert them into HTML <span>
elements. In the template rule, you can use an attribute value template, so you can make your <span class="{AVT}"
be the the value of the @type
on the <punc>
elements as XSLT processes them. Does that make sense? You've written this kind of code before.
Okay, I see what I was doing wrong!
Thanks, I'll give that a try!
@kes213 Just to be clear, I would not use <xsl:mode on-no-match="shallow-copy"/>
here. Instead you want to write a new template rule to convert the elements you want to toggle into HTML <span>
elements.
Where should I put the new template match on
@kes213 It's simply a new template rule, and it can really go anywhere in your XSLT file. You can put that template rule anywhere because you already have this rule in place:
<xsl:template match="stanza/l">
<xsl:apply-templates/>
<br/>
</xsl:template>
Because you have that rule, you are all set to apply whatever template rules process elements that might be inside the <l>
elements in your XML. XSLT doesn't care in what order you set your template rules--they will fire as long as they encounter a rule to process them, and if they do not, they'll default to outputting plain text.
Okay, I added this template match:
<xsl:template match="punc">
<span class="{@type}"></span>
</xsl:template>
The elements are on the output, but the punctuation marks that should be between the tags are gone. Do I need to put something else in between the tags to get the commas, periods, etc. to appear as well?
Oops, I see what I did. I didn't put my <xsl:apply-templates/>
in between them.
@kes213 And of course you can process your figurative language elements with a template rule much like that one you've just written.
Yes! Thank you!
Okay, I've gotten past my HTML output problems.
I've finished putting together my JavaScript file and pairing it with my HTML and the CSS documents, but it's not working (meaning it's not highlighting the punctuation marks like it should).
I uploaded my HTML file, my CSS file, and my JavaScript file to the Troubleshooting folder. I created a new folder called STINEBISER so that all 3 would be held together.
@kes213 Aha! I see the problem--this is a proofreading issue! When I look at your CSS, I see:
span.commas.on {color:purple}
span.periods.on {color:white}
span.semicolons.on {color:green}
...
But when I look at your HTML, I see:
My heart<span class="comma">,</span> my heart is lonely<span class="period">.</span>
<br/>
I think the mismatch is in your JavaScript as well. Be careful! You want to make sure these all match up exactly.
@kes213 More of the CSS classes are mismatched--I just posted those three for a quick overview of the problem.
Also, you might want to think about giving the values up in your checkbox area a stable class of their own so they show what the elements will look like when they're highlighted. You could just set those to toggle on
as well, though.
I see the proofreading problem!
By "a stable class of their own," do you mean highlighting the checkbox labels to match the highlighted text? Does that mean I should add another attribute value to the html elements?
Changing the proofreading issues didn't make the checkboxes work.
@kes213 Uh oh...let's take another look to debug the code...
About the checkboxes...Yes, I was thinking you could highlight your checkbox labels so people can always see what the highlighting will look like when they click, and you could give the <span>
elements in your input field something distinctive for CSS to find.
@kes213 I wasn't looking closely at your JavaScript before, but I see lots of the same kind of error now that I look at it. For example, I see:
case "CommasToggle": {
var commas = document.getElementsByClassName("commas");
for (var i = 0; i < commas.length; i++) {
chars[i].classList.toggle("on")}};
There is no variable named "chars" here. (That was my variable name from the sample.) You've named your variable commas
, so you need to use that. Check each one of these...
I figured it was an oversight as I was adapting your code.
I'll change those and try again!
@kes213 Also-- I notice that some of your cases are lacking that crucial last line where you step on each member of the variable list to toggle it on! For example, notice:
case "Open_PsToggle": {
var open_p = document.getElementsByClassName("open_parentheses");
for (var i = 0; i < open_p.length; i++) {}};
break;
It's missing the line that should be
open_p[i].classList.toggle("on")}};
break;
I believe it's working now! Thank you!
@kes213 Huzzah!!! :-D It's always a big triumph when you get all your files to work together the first time! :-)
For JavaScript Exercise 2, I'm making an html page that displays all of the Harlem Ren Project's Claude McKay poems.
I have green html file output that formats the page how I want it. However, the JavaScript Exercise 2 assignment requires elements for the javascript coding. I want to wrap my elements in elements, and the @class attributes will then basically match each other. That way, I can create a list similar to the one that Dr. Bondar uses for "The Injured Islanders" page.
My problem is that I don't know how to get my elements to output on my html page that I created with XSLT.
Here is my XSLT:
And here is a sample of my HTML Output:
If it helps, both of these files are currently uploaded on the Harlem_Ren GitHub repo.
Can anyone tell me how I can get the elements to turn out on the html output? I'm thinking I need a new template match, but I'm not sure.