newtfire / textEncoding-Hub

shared repo for DIGIT 110: Text Encoding class at Penn State Erie, The Behrend College
https://newtfire.github.io/textEncoding-Hub/
Creative Commons Zero v1.0 Universal
17 stars 1 forks source link

string-join() to create list #28

Closed alexvanwoert closed 3 years ago

alexvanwoert commented 3 years ago

To output a string-joined list of locations in my table for each chapter I tried There is no data outputted in my table. I expected to output the list because I am calling on the element location and separating it by commas. I have tried using variables and reformatting but I cannot seem to get any output. I have no idea what I am doing wrong or where to go from here to get a string list.

ebeshero commented 3 years ago

@alexvanwoert Sorry I didn't see this until now! I addressed this with you over Canvas, but it will help to take a look at the template rule in which you've set your <xsl:value-of select="..."> statement. It's important to note the context node for your <xsl:template match="...">.

To get your rule to output anything, you'd need to add one more forward slash to the beginning to start at the document node and go down the tree like so: <xsl:value-of select="string-join(//root/title/chapter/p/location, ', ')"/>. However, if you did so, you would output ALL the locations in ALL the chapters at once, and you almost certainly don't want to do that. You just want the locations within each specific chapter. So that is why you want to define this from the context of your template match node. If that is set up as I expect it is, it'll look like this:

<xsl:template match="chapter">
    <tr>
        <td>....</td>
        <td><xsl:value-of select="string-join(descendant::location, ', ')"/></td>
        <td>....</td>
    </tr>
</xsl:template>

You could also write that as:

<xsl:template match="chapter">
    <tr>
        <td>....</td>
        <td><xsl:value-of select="string-join(.//location, ', ')"/></td>
        <td>....</td>
    </tr>
</xsl:template>

But be careful to apply the dot . because you need to prevent it from starting at the document node and spitting out ALL the locations in the whole novel! Using descendant:: or .// means, "go down the tree from the starting point of the context node which is the chapter."

ebeshero commented 3 years ago

@alexvanwoert Also, when you see output, you'll also see lots of duplicates. So...you may wish to return distinct-values() before you do the string-join().