Skip to content
This repository has been archived by the owner on Aug 22, 2020. It is now read-only.

XSLT 2 #155

Closed
laurenmcguigan opened this issue Feb 29, 2016 · 36 comments
Closed

XSLT 2 #155

laurenmcguigan opened this issue Feb 29, 2016 · 36 comments

Comments

@laurenmcguigan
Copy link
Collaborator

I am a little confused on how to start the stylesheet. Do you want it to start like an html document? like:
<xsl:template match="/"> <html> <head> <title>Lauren XSLT</title> </head> <body> <body> </html>

And if so, where do I go from there?

@laurenmcguigan
Copy link
Collaborator Author

`<xsl:template match="/">
    <html>
        <head>
            <title>Lauren XSLT</title>
        </head>
        <body>
           <xsl:apply-templates select="/head"/>
            <xsl:apply-templates select="/articleBody"/>
            <span class="nellVoice">
                <xsl:apply-templates select="nellVoice"/>
            </span>
        </body>
    </html>
    </xsl:template>`

What am I doing wrong here?

@laurenmcguigan
Copy link
Collaborator Author

or is it like this?

`<xsl:template match="/">
    <html>
        <head>
            <title>Lauren XSLT</title>
        </head>
        <body>
           <xsl:apply-templates select="/head"/>
            <xsl:apply-templates select="/articleBody"/>
        </body>
    </html>
    </xsl:template>

<xsl:template match="nellVoice">
<span class="nellVoice">
    <xsl:apply-templates/>
</span>
</xsl:template>`

Am I doing this right so far?

@laurenmcguigan
Copy link
Collaborator Author

Also, for number 3 I have been trying to use this:

<xsl:template match="//workingConditions/@category=/toneElements/@tone">

which I know is wrong but I'm not sure what exactly it is asking me to do.

@laurenmcguigan
Copy link
Collaborator Author

@mmm202 @mjb232 @jlm323 Have any of you done this yet? Or know what is going on?

@ghbondar
Copy link
Collaborator

@laurenmcguigan Yes, you seem to be on the right track. Now, to style the different kinds of info in the head-element. Regarding #3: try accessing the attribute-axis as an XPath predicate.

@laurenmcguigan
Copy link
Collaborator Author

@ghbondar thank you. So I tried this
<xsl:template match="//workingConditions[@category]=/toneElements[@tone]">

but oxygen doesn't like the =
Is there something I need to add to this or something I need to do instead of an equal sign?

@laurenmcguigan
Copy link
Collaborator Author

Also, nothing is appearing in my output when I transform it to HTML. I think it is due to a problem I am having in the beginning of my stylesheet but I'm not sure what. Should all the transformations be included in the body element?

@ebeshero
Copy link
Owner

@laurenmcguigan Try it with just one predicate with an '=' inside: You did this sort of thing inside a Schematron test before: Think of the //workingConditions as your context and the stuff in the predicate as your test. So you want to find all the //workingConditions where [@category = //toneElements/@tone] Be careful about exactly what you're saying is equal here! It's an attribute on one element to an attribute on another element!

@ebeshero
Copy link
Owner

@laurenmcguigan You'll want to review the XSLT tutorial and look at some sample stylesheets, I think, to remind yourself how template matches work. Remember that what we do in transforming to HTML is we have to make one template rule on the document node, because we have to change the basic structure of the document: XML to HTML. The template rule that matches the document node contains the structural elements that sit in a one-to-one relationship (because there's just one document node). So you write your outer body html elements there.

But anything repeatable like body paragraphs, and the salad of elements inside those (whatever they are) gets its own new template rule after that one on the document node, because that's the sort of thing that XSLT is really good at! You refer to the templates that need to fire from inside each template rule with <xsl:apply-templates>. So the big template rule, the one matching on the document node that sets up your HTML file, hits an apply-templates that's supposed to fire any other template rules you've written. And if you haven't written any, the default rules apply and spit out plain text, consuming all your elements. Hope that works as a sort of crash review, but do go back and read the tutorials and examples carefully! And also, push your code into the Troubleshooting folder here in the DHClass-Hub and we'll take a look at it, those of us awake!

@ebeshero
Copy link
Owner

@laurenmcguigan One thing I notice in the code you're posting here is you're using a lot of single slashes (/), when I think you mean double slashes: (//). The first single slash says, start at the document node. (And it's appropriate to use that as your template @match value for the special document-node template rule to set up your HTML document.) But when you are stepping down from the document node, a single slash means, look only at my immediate children. I think you don't mean to do that, do you? You want to look down deep into the descendant axis.

When you write your template rules that match on XPath patterns (other than the document node), it's a little different. You'll be understood to be stepping down, or looking up, or going preceding or following, etc. in relation to wherever you set your XPath @match, so if that was any paragraph in the body (<xsl:template match="p">) you'll want to indicate where to go from there in your apply-templates if you want something specific to happen around, say, a <place> element . Remember how we wrote such things in Schematron, moving from <rule context="XPath Pattern"> to <assert test="specific XPath from that pattern match">, and that should help!

@laurenmcguigan
Copy link
Collaborator Author

@ebeshero I pushed it to the trouble shooting folder its lmcguigan_02-29_XSLT02. Im getting an output now but it is a little odd. Not sure why.

@laurenmcguigan
Copy link
Collaborator Author

@ebeshero but your advice really helped, I think I'm more on the right track now. Thank you!

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

im having trouble associating my CSS with my XSLT output. I have this:
<head> <?xml-stylesheet type="text/css" href="Nell.css"?> </head>
The CSS association should go in the head element, but when I transform my XSLT I don't get any results. I checked the TEXT of my output and the CSS isn't even appearing.

@laurenmcguigan
Copy link
Collaborator Author

@mjb232 it should be <link rel="stylesheet type="text/css" href="Nell.css"/>
And remember it is a self closing tag

@laurenmcguigan
Copy link
Collaborator Author

<xsl:template match="//workingConditions[@category=/toneElements[@tone]]"> <span class="bad"> <xsl:apply-templates select="@tone='bad'"/> </span> </xsl:template>

I tried this instead on my XSLT but it isn't working either. Is this closer than what I had before?

@jlm323
Copy link
Collaborator

jlm323 commented Feb 29, 2016

I have this but nothing is showing up at all:

<xsl:template match="//toneElements[@category = //toneElements/@tone]"> <span class="good"> <xsl:apply-templates select="@tone='good'"/> </span> <span class="bad"> <xsl:apply-templates select="@tone='bad'"/> </span> <span class="neutral"> <xsl:apply-templates select="@tone='neutral'"/> </span> </xsl:template>

Do I need to create a new xsl:template for each span?

@laurenmcguigan
Copy link
Collaborator Author

@jlm323 I tried each one with their own xsl:template, and it isn't working for me either...

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

Ok so I cant get my femVoice, mascVoice, and nellVoice to change colors. My CSS is associated and my XSLT is wrapping each voice in the correct mark-up, but I don't think my actual CSS is right. I have:
span.nellVoice{ color:purple; }
and my actual tag on the nellVoice looks like this:
<span class="nellVoice"> TEXT </span>
what am I doing wrong?

@jlm323
Copy link
Collaborator

jlm323 commented Feb 29, 2016

I'm having the same problem. Your CSS looks right to me, but I'm not sure why it's not showing up for either of us.

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

I know my CSS is definitely associated with my HTML (to test to see if their associated put body{background:} in your CSS, save it, and transform your document and look at the result.). So It has to be an issue with the CSS itself but I dont know what it is. Thoughts @ebeshero?

@laurenmcguigan
Copy link
Collaborator Author

@mjb how are you getting the span elements to show up in your output??

@mjb232 mjb232 closed this as completed Feb 29, 2016
@mjb232 mjb232 reopened this Feb 29, 2016
@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

Ummmmmmmm sorry about that, I'm not sure what I just did haha.

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

Anyway, check to see if your matches are catching the right elements. You can do this by running whatever you have in your match in xpath. If everything is working as it should, when you look in the Text of the output (you can toggle between the Text and XHTML versions by clicking which ever you prefer at the bottom of the output window).

@laurenmcguigan
Copy link
Collaborator Author

@mjb i dont think //workingConditions[@category=//toneElements[@tone]] is supposed to show up in Xpath, or is it? If so, so you see what is wrong with mine that it isn't showing any results?

@jlm323
Copy link
Collaborator

jlm323 commented Feb 29, 2016

It seems like my matches are mostly catching the right elements but the CSS just isn't showing up in the output. I tried changing the background color and it worked, so they're associated, but nothing else works!

The only match that isn't catching is the workingConditions, like @laurenmcguigan . I'm not sure it's the right xPath expression.

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

Ok, so what are we trying to find in xpath for number three?

@laurenmcguigan
Copy link
Collaborator Author

@mjb232 @jlm323 this is what my XSLT looks like
<xsl:template match="//mascVoice[@connotation=/toneElements[@tone]]"> <span class="bad"> <xsl:apply-templates select="@tone='bad'"/> </span> <span class="good"> <xsl:apply-templates select="@tone='good'"/> </span> </xsl:template>

but nothing is even showing up in the xml like you guys, there are no more tags for mascVoice. What am I doing wrong?

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

so for my mascVoice, femVoice, and nellVoice, I found that simply using
//mascVoice or //femVoice or //nellVoice all worked fine.

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

For my working conditions i did
match="workingConditions[@category='negative']

@laurenmcguigan
Copy link
Collaborator Author

@mjb but the working conditions element can have 6 other categories

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

Ok, I see. Let me work with it for a little.

@jlm323
Copy link
Collaborator

jlm323 commented Feb 29, 2016

We're trying to basically put all of the categories of working conditions and it's tone in the match and then create spans that differentiate the tones. I still can't figure it out so I'm heading to bed now.

Also there isn't a upload point on Courseweb for XSLT Exercise 2 yet! @RJP43 @nlottig94

@mjb232
Copy link
Collaborator

mjb232 commented Feb 29, 2016

Yeah, I think I'm at that point myself. I'm going to work on the rest of my document and just see if we can go over 3 tomorrow.

@ebeshero
Copy link
Owner

@laurenmcguigan @mjb232 @jlm323 @mmm202 I saw this in the code Lauren posted, but the chatter suggests you're all having a little trouble with your CSS...I see where it is: You have the right CSS line, but it's sitting in the wrong place.

Your CSS line, Lauren, is:

 <link rel="stylesheet" type="text/css" href="lmcguigan_02-29_XSLT02.css"/>

But it needs to go *inside the <html><head>....</head> element as it would in any HTML file! It's not being output because it's not sitting in your template rule where you build up your HTML document.

@ebeshero ebeshero reopened this Feb 29, 2016
@ebeshero
Copy link
Owner

Oops! I didn't mean to close that issue!

@jlm323
Copy link
Collaborator

jlm323 commented Feb 29, 2016

I figured it out! I fixed my CSS by removing the "span" from the CSS so it looks like this:
.good { color: #00b300;}
instead of:
span.good { color: #00b300;}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants