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

XSLT 3 #567

Closed
Julegirl opened this issue Oct 31, 2018 · 13 comments
Closed

XSLT 3 #567

Julegirl opened this issue Oct 31, 2018 · 13 comments

Comments

@Julegirl
Copy link
Collaborator

Julegirl commented Oct 31, 2018

I am so stuck. I was able to get my headings just fine, but I can't get the contents to go where they are supposed to. I don't know what to do or say for the output. I know that <tr> represents tabel row and <td> represents the data for the row and I know how to put stuff there, but I do I put in the right contents?

@ebeshero
Copy link
Owner

Hi @Julegirl ! I just added some of those tick marks to your code so we can read your post more clearly. Okay, so just start by seeing if you can set up your template rules in the right place. I think @BMT45 was stuck where you are yesterday, so take a look at the issue he posted and our responses: #566

@ebeshero
Copy link
Owner

ebeshero commented Oct 31, 2018

@Julegirl Let me see if I can help a little more here, too. You mentioned you have your table headings just fine, so that tells me you've got your template rule that matches on the document node, and you're outputting the <table> element and its top header row, right?

Now, you want to be able to select what part of the tree you want to process for the rest of that table. This is where you want to use <xsl:apply-templates select="descendant::fs[the-ones-with-the-Yes-answers]"/>, like this:

<xsl:template match="/">
<html>
      <head><title>STUFF</title></head>
<body>
<table>
     <tr> 
           <th>.....TABLE HEADER STUFF....</th>
     <tr>
   <xsl:apply-templates select="select="descendant::fs[the-ones-with-the-Yes-answers]"/>
<table>
</body>
</html>
</xsl:template>

After this, you need a NEW template rule next that will match on those <fs> elements that have "Yes" answers in them. Every time that template rule matches something in the tree, you want to output a new table row containing its data. Does that help? (Also see the issue @BMT45 posted for more sample code).

@Julegirl
Copy link
Collaborator Author

Yeah, I got that far, but I don't know where to go from here. It's just that how you worded everything i confusing me greatly.

@ebeshero
Copy link
Owner

@Julegirl Quote where you're confused, and I'll see if I can improve it...?

@Julegirl
Copy link
Collaborator Author

Julegirl commented Oct 31, 2018

It's #3 and 4
" 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 descendant elements, based on their contents. In order to specify that you only want specific Yes or No Questions then you need to specify with <xsl:apply-template select="___"> to process fs elements only when one of the has an @select="Yes". That work wll get done by new xsl:template rules that you will need to write to match the with @select="Yes".

"In the xsl:template rules for elements of the you’ll need to output something for each one, that is, each question that has a “Yes” answer (held inside the same element as the with @select="Yes")."

I just don't understand what your asking, or how I'm supposed to do it. It sounds like you want us to do the same thing over and over again.

@ebeshero
Copy link
Owner

@Julegirl Okay, I pretty much was writing about exactly that in this issue here on DHClass-Hub. Take a look at the code block I posted--the point is just explaining why you need to use a @select attribute on <xsl:apply-templates>.

  • You need to tell it to go and process the <fs> elements that have "Yes" answers in them. So you need that <xsl:apply-templates select=".....">

  • Then, after you CLOSE the template rule that processed the document root element, you need to write a NEW template rule to match on those <fs> elements, like this:

<xsl:template match="fs[the-ones-that-contain-Yes-answers]">
      <tr>
           <td><xsl:value-of select="count(...)"/><!--table row count here: count the preceding fs that has a Yes answer + 1 --></td>
           <td><!--question string here.  --> <xsl:apply-templates select="XPath-to-the-Question"/></td>
          <td> <!--Number of yes answers, pulled from an attribute value: you can use <xsl:apply-templates again or <xsl:value-of select="..."/> --></td>
       <!--  MORE <td> elements with <xsl:value-of select=".."> or <xsl:apply-templates select="..."/> to grab the data you want to go in the table cells.</td>-->
      </tr>
</xsl:template>

Does that help?

@Julegirl
Copy link
Collaborator Author

Julegirl commented Oct 31, 2018

It helps a little bit.

@Julegirl
Copy link
Collaborator Author

Looks like I'm running into a computer error. It says that I reached my maximum number of xsl:template instructions. I'm just going to turn in what I can and hopefully figure out where I went wrong tomorrow.

@ebeshero
Copy link
Owner

ebeshero commented Oct 31, 2018

@Julegirl If you want to push your code here to the Troubleshooting folder, we can help debug it...Make sure you're starting your @select attribute on <xsl:apply-templates> using the descendant:: axis (no leading double-slash there!)

@Julegirl
Copy link
Collaborator Author

It's ok, I figured out why it was doing that. I'm good. And thanks for the 'no double-dash' tip. That was screwing me up.

@ebeshero
Copy link
Owner

Hooray for a successful debugging! You're learning some serious coding skills!!! :-D

@ebeshero
Copy link
Owner

@Julegirl That was one of my big mistakes in learning XSLT, too. I remember being really upset over the looping for quite a while, so I remember very vividly how to fix it as a result!!!

@Julegirl
Copy link
Collaborator Author

Thanks, but either way, I'll turn in what I can and figure it out tomorrow. I'm starting to lose brain power.

@ebeshero ebeshero closed this as completed Jan 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants