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

Confused #47

Closed
CodyKarch opened this issue Oct 22, 2015 · 59 comments
Closed

Confused #47

CodyKarch opened this issue Oct 22, 2015 · 59 comments

Comments

@CodyKarch
Copy link
Collaborator

I was looking at the class example versus our homework instructions, and I noticed that the class example held much information in elements, but our homework information was in the attributes; how are we supposed to pick out the information from there? And also, I don't understand this (which I think has to do with my question): In this case, then, your <xsl:apply-template> elements inside the template rule for the document node will tell the system that you want to process the <string> elements of the <f name="question"> and all of the corresponding responses (<f name="response">) and the corresponding <string> insides of the <f name="note"> element all sitting inside of the same <fs> element. In order to specify that you only want specific Yes or No Questions then the <xsl:apply-template> elements inside the template rule for the document node will tell the system that you want to process the following elements only when one of the <f name="response"> has an @select="Yes", at which point the template rule for the document node will call out what portions of the document need to be processed at this particular point. That work actually gets done by other <xsl:template> rules, the ones that you’ve written that match the <f name="response"> with @select="Yes". @ebeshero

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

To select on anything using XSLT <xsl:apply-templates select="..."/> you are going to need to write an XPath function and you know how to get to attributes using XPath. So there should be no real problem for you to grab attributes. The question is asking you to make a match and initial selection on the elements that are bound together with similar responses (the yes and no questions). Check out the last issue Nicole posted and maybe this will give you some insight.

@CodyKarch
Copy link
Collaborator Author

I understood what you referenced, but I still can't comprehend what is told in the instructions mentioned above (and additionally, now, number 3: In the <xsl:template> rules for <string> elements of the <f name="question"> you’ll need to output something for each one, that is, each question that has a “Yes” answer (held inside the same <fs> element as the <f name="response"> with @select="Yes").). I feel like if I understood those, I could continue along.

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

The assignment is having you take note of what is bound together and how you make selections on information while keeping what is bound together... together.

Ok let's walk through this then ... what do you need to select to get only the questions and answers that contain a possible yes/no response?

@CodyKarch
Copy link
Collaborator Author

Well, I was able to collect the questions with: <tr> <td><xsl:apply-templates select="f[@name='question']/string"/></td> </tr> and I know that if I want to collect more info, I need to put another apply-template in another set of elements; right?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

Ok so what is really great about our <fs> structure is that all the information for one <tr> are in the same <fs> so if you do a match that grabs a <fs> that contains a possible response of yes or you could choose no or any other response that is specific to yes or no questions then all of your selections <apply-templates select=".."/> can be made inside of that one match and for each selection you would open a new <td> inside of that same <tr> inside of that one match... looks like you get it with your selection for grabbing the questions. It is hard for me to judge what you have with your matches and understand where you are getting confused without your file. Consider pushing to the troubleshooting folder if I am not being helpful enough and perhaps I can be of more help.

@nlottig94
Copy link
Collaborator

You need to fix something in your firstxsl:apply-templates select="....." You're being way too greedy just grabbing the <fs> elements....try digging down deeper!

@CodyKarch
Copy link
Collaborator Author

Into the attributes?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

exactly so in both your first select and your first match you are saying give me all the <fs> you only want the <fs> that have certain responses ... this is a predicate issue

@nlottig94
Copy link
Collaborator

Yes and no. You first want to go down into <f> elements and then you want to select different attributes to make your search more specific..

@nlottig94
Copy link
Collaborator

I was telling the XSLT to give me all of the elements in the <div> element. I was using a greedy selection because it was too much.
I needed to find the more specific XPath of grabbing all of the <fs> elements that have <f> elements which have @name="response" and @select="no". This will grab all of the yes and no questions because the yes is bound to the no.

@CodyKarch
Copy link
Collaborator Author

Okay, I'm really trying here. I need to change the apply-template which is within the

? Or do I need to change the template after my HTML?

@CodyKarch
Copy link
Collaborator Author

Sorry <table?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

both ... but you need to understand your first selection before you start to thinking about what you would select later.

@CodyKarch
Copy link
Collaborator Author

So would <xsl:apply-templates select="//fs/f"> be suitable for the first one?

@CodyKarch
Copy link
Collaborator Author

Or do I need more on that?

@blawrence719
Copy link
Collaborator

You need more than that. You need to go deeper into your <fs> and say exactly which <f> you are trying to grab for your table.

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

yes! and remember what I hinted to about using a predicate so you don't step down any further but you do specify what <f> you want

@CodyKarch
Copy link
Collaborator Author

So, I keep testing different things, but it keeps popping up "Infinite Loop Detected"; what does this mean?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

show me what you are testing just copy it here into this issue with tics ..

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

you were on the right track with going into the <f> of the <fs> <xsl:apply-templates select="//fs/f"> just take it further by specifying what <f> responses your table is specifically looking for using predicates

@CodyKarch
Copy link
Collaborator Author

      ` <table>
                <tr>
                    <th>Number</th>
                    <th>Question</th>
                    <th>Yes</th>
                    <th>Yes, but fined</th>
                    <th>No</th>
                    <th>Blank</th>
                    <th>Total Responses</th>
                </tr>
                <tr>

                </tr>
                <xsl:apply-templates select="//fs/f[@name='response']"></xsl:apply-templates>
            </table>

        </body>

    </html>

</xsl:template>

<xsl:template match="//fs/f[@name='response']">

    <tr> 
        <td><xsl:apply-templates select="//fs/f[@select='Yes']"/></td>


    </tr>
</xsl:template>`

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

and consider that the / going into the f is saying you only want the <f> s in reality you want the <fs> that has the <f> that has the @select

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

where are you Cody? I am still on campus and I feel like this is an issue with how we are explaining it through typing that you aren't catching what we are hinting at ... I am in The Shaw with Brook and Nicole

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

You are getting closer ...

@CodyKarch
Copy link
Collaborator Author

I'm in westmoreland. Would select="//fs/f[@select]" be right?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

yes yes yes but @select= to what???? to get yes or no questions specifically and your first select will be almost identical to your first match so then all of your table cells will have info that is bound together in the same <fs>

@CodyKarch
Copy link
Collaborator Author

and for all three spots shown above? or just the first?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

so after you have selected and matched ... the selections you make in the single <td> elements will only have to specify exactly what you want like how you originally had for the question strings

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

you need to make the bind first then output each part of what is bound together and needs to be represented in the table cells

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

by saying //fs/f you are saying give me all the <f> elements that come after <fs> elements you actually want to say give me all the <fs> elements that have <fs> that have @select=".." and the contents of the select will be a specific value either yes, no, or yes but fined so that you get the <fs> elements that are related to yes or no questions

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

pay special attention too that you spell the specific value you choose the same way it is spelled in the xml

@CodyKarch
Copy link
Collaborator Author

Strangely, I have tried this ^mentioned above and every order I try with these doesn't work (in one manner or another)

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

predicate inside predicate is specifying the <fs> that has something that has something. From what I see you have the / which is stepping down into the <f>

@CodyKarch
Copy link
Collaborator Author

So I need an fs that contains an f that contains a select attribute with either Yes or No ? Correct?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

right but the contains are written how exactly .. show me in tics

@CodyKarch
Copy link
Collaborator Author

//fs[f(@select='Yes')] ?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

<xsl:apply-templates select="//fs[f thats good ....

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

and @select='yes' is good but needs to be in what to say the <f> that have those

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

predicate inside predicate is how you specify

@CodyKarch
Copy link
Collaborator Author

So, instead of parenthesis, I would use square brackets?

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

yes!!!!! because we are talking predicates :) now read what you have in that selection and tell me how it is different from what you had ... its important you understand where this first match/select is putting you so you can make your other selections

@CodyKarch
Copy link
Collaborator Author

So, would I want to have it like this:
1st: apply-templates select="//f[f[@select='Yes']]"
2nd: templates match="//f[f[@select='Yes']]"
3rd: apply-templates select="//f[f[@select='Yes']]"

Ps: I kind of wish I could have simply grasped the quotation I first posted.

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

well think about this once you make your second match you then want to start with outputting a new <tr> and all the <td> in the specific order of your <th> elements from above... this is why I was saying you were on the right track with grabbing your question strings once you have the right initial select and match

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

now that you have said I want the <fs> elements of a specific type you can say you want the question number, the question, each of the responses, and the sum of responses all in a single <tr> all inside that match that binds them together

@RJP43
Copy link
Collaborator

RJP43 commented Oct 23, 2015

go back to the assignment and i think u can figure it out from here

@CodyKarch
Copy link
Collaborator Author

So:
1st: apply-templates select="//f[f[@select='Yes']]" *** I don't know what you mean by question number, I don't see any. ***
2nd: templates match="//f[f[@name='question']]"
3rd: apply-templates select="//f[f[@name='response']]"

@ebeshero
Copy link
Owner

@CodyKarch @RJP43 Careful, folks, with those // marks and where you're using them! Cody, I wonder if that was what was giving you the infinite loop problem. When you say
xsl:template match="something" that is not a literal XPath: it's a pattern. And you step down from that pattern inside the template rule when you do xsl:apply-templates select="something" or xsl:apply-templates select=".//something"
That dot notation is significant--and you may not need it here, but you need to remember how you're stepping from the template match (your context node) down into its children and/or descendants, or wherever you need to walk with XPath in your @select attribute.

@ebeshero
Copy link
Owner

@CodyKarch @RJP43 When you write
<xsl:apply-templates select="//f[ANYTHING]"/>
you are saying, GO BACK UP TO THE DOCUMENT NODE and run through the ENTIRE XML tree to get all these. Is that what you intended?

@CodyKarch
Copy link
Collaborator Author

Well, isn't that saying descend to the f element and find specifically ANYTHING ?

@ebeshero
Copy link
Owner

Yes--and it'll probably work here, and might even get you the output you want--but it could get you TOO MUCH of that output, if you only want ANYTHING when it's a piece of a PARTICULAR fs element.

@ebeshero
Copy link
Owner

What I'm saying is, there's a simpler way to write your path steps here, if you're thinking about how XSLT template matches and apply-templates @select attributes work. Step down, parent to child to attribute.

@CodyKarch
Copy link
Collaborator Author

So you want the most direct path to a specific thing?

@ebeshero
Copy link
Owner

Yep! 👍

@ebeshero
Copy link
Owner

Keep it simple so you don't make your processor loop around unnecessarily. Sometimes you may actually want to go back up to the document node, but do you really need to do that here?

@CodyKarch
Copy link
Collaborator Author

No. You're setting a place within the HTML with your apply-template, giving it a governing rule of which is a connecting template, and pulling out your information with another apply-template. And you wouldn't want an indirect path for any of those. Correct?

@ebeshero
Copy link
Owner

Correct: There is no need of an indirect path.

@CodyKarch
Copy link
Collaborator Author

SO should my XPath in the HTML and my XPath that starts a template be the same?

@ebeshero
Copy link
Owner

Maybe not exactly the same... but my solution doesn't have //'s in it.

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