haggis78 / BreconChurch

Files for our DH project on Henry VIII's Letter Patent founding Brecon Collegiate Church in Wales.
3 stars 0 forks source link

XSLT #19

Closed haggis78 closed 4 years ago

haggis78 commented 4 years ago

Can someone set me straight on this XSLT? I'm trying to output a single line in an html document that should read "Witnesses R and W: 119". Instead, I'm clearly getting this to match on each of the 119 instances where Witnesses R and W both appear, so it gives me the desired output, 119 times instead of once! I think I could come up with an ugly fragile brute-force kludge to trim that back down to one, but I'm sure there's a more elegant solution.

` <xsl:template match="/">
    <html>
        <head>
            <title>Analysis</title>
        </head>
        <body>
            <h1>Analysis of textual relationships among witnesses</h1>
            <h2>Numerical analysis</h2>
            <ul>
                <xsl:apply-templates select="//rdg[contains(@wit, 'R') and contains (@wit, 'W')]"/>
            </ul>
              </body>
    </html>
</xsl:template>

<xsl:template match="rdg">
    <p>Witnesses R and W: <xsl:value-of select="count(//rdg[contains(@wit, 'R') and contains (@wit, 'W')])"></xsl:value-of></p>
</xsl:template>`
ebeshero commented 4 years ago

@haggis78 If I understand correctly, you want a count of the number of times witnesses R and W both appear. If that's what you need, you just want to send your sequence of 119 nodes to the XPath count() function. You want to apply that function just once, so you want to create your list up in the template match on the document node. (I can imagine you using SVG elements in this way, too: send the count of 119 to a line element.) Does that help?

haggis78 commented 4 years ago

@ebeshero I get that in theory, yes. I understand the principle behind what's going wrong, and I know that I want it to apply the function just once -- I just haven't figured out how to accomplish it. When you say "you want to create your list up in the template match on the document node", do you mean all the way up at

?
ebeshero commented 4 years ago

@haggis78 Yes, that’s right. You don’t want a template to match on those <rdg> elements one at a time to output 119 of them. You want to return a single count of all of them.