Comments (59)
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.
from dhclass-hub.
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.
from dhclass-hub.
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?
from dhclass-hub.
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?
from dhclass-hub.
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.
from dhclass-hub.
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!
from dhclass-hub.
Into the attributes?
from dhclass-hub.
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
from dhclass-hub.
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..
from dhclass-hub.
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.
from dhclass-hub.
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?from dhclass-hub.
Sorry <table
?
from dhclass-hub.
both ... but you need to understand your first selection before you start to thinking about what you would select later.
from dhclass-hub.
So would <xsl:apply-templates select="//fs/f">
be suitable for the first one?
from dhclass-hub.
Or do I need more on that?
from dhclass-hub.
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.
from dhclass-hub.
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
from dhclass-hub.
So, I keep testing different things, but it keeps popping up "Infinite Loop Detected"; what does this mean?
from dhclass-hub.
show me what you are testing just copy it here into this issue with tics ..
from dhclass-hub.
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
from dhclass-hub.
` <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>`
from dhclass-hub.
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
from dhclass-hub.
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
from dhclass-hub.
You are getting closer ...
from dhclass-hub.
I'm in westmoreland. Would select="//fs/f[@select]"
be right?
from dhclass-hub.
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>
from dhclass-hub.
and for all three spots shown above? or just the first?
from dhclass-hub.
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
from dhclass-hub.
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
from dhclass-hub.
and in your first selection and match you are not trying to find the <f>
elements you want the <fs>
elements
from dhclass-hub.
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
from dhclass-hub.
pay special attention too that you spell the specific value you choose the same way it is spelled in the xml
from dhclass-hub.
Strangely, I have tried this ^mentioned above and every order I try with these doesn't work (in one manner or another)
from dhclass-hub.
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>
from dhclass-hub.
So I need an fs
that contains an f
that contains a select
attribute with either Yes
or No
? Correct?
from dhclass-hub.
right but the contains are written how exactly .. show me in tics
from dhclass-hub.
//fs[f(@select='Yes')]
?
from dhclass-hub.
<xsl:apply-templates select="//fs[f
thats good ....
from dhclass-hub.
and @select='yes'
is good but needs to be in what to say the <f>
that have those
from dhclass-hub.
predicate inside predicate is how you specify
from dhclass-hub.
So, instead of parenthesis, I would use square brackets?
from dhclass-hub.
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
from dhclass-hub.
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.
from dhclass-hub.
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
from dhclass-hub.
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
from dhclass-hub.
go back to the assignment and i think u can figure it out from here
from dhclass-hub.
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']]"
from dhclass-hub.
@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.
from dhclass-hub.
@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?
from dhclass-hub.
Well, isn't that saying descend to the f element and find specifically ANYTHING ?
from dhclass-hub.
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.
from dhclass-hub.
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.
from dhclass-hub.
So you want the most direct path to a specific thing?
from dhclass-hub.
Yep! π
from dhclass-hub.
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?
from dhclass-hub.
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?
from dhclass-hub.
Correct: There is no need of an indirect path.
from dhclass-hub.
SO should my XPath in the HTML and my XPath that starts a template be the same?
from dhclass-hub.
Maybe not exactly the same... but my solution doesn't have //'s in it.
from dhclass-hub.
Related Issues (20)
- HTML Semantic Elements for structuring a page
- Steve Ramsay: "The Hermeneutics of Screwing Around" and "In Praise of Pattern" HOT 13
- NEWS HOT 2
- XPath format-date() picture strings
- First XQuery over Banksy from class today
- Saving XQuery Files
- Network Analysis HOT 16
- Schematron Quick Fix HOT 1
- SOS: Cytoscape is my mortal enemy HOT 8
- M 3/23 Class Sign-in HOT 12
- Slack Chat for DH class
- Semester project presentations HOT 1
- zoom video HOT 3
- Date Arithmetic for Data Visualization: User-Defined Functions in XQuery
- Resources on JavaScript Properties, Methods, Events
- Upcoming Presentations!
- Choose a Creative Commons License for Your Project
- Friday April 17: Presentation Day and Feedback!
- XPath: Taking Average of values derived by a FLOWR statement HOT 8
- Extended due date for semester projects in the quarantine semester
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dhclass-hub.