Open khuber116 opened 5 years ago
@khuber116 Look at the @y
values in your angle-bracketed output. General lesson: if you don’t see what you expect, look at the values, and not just the (non)picture.
The following is just one version of what I've been working on. When I try this I receive an error message telling me that I'm trying to divide by zero. I have tried many different things to try and select the values I want but I can't seem to get there. Any help would be appreciated.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/2000/svg"
version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<svg height="375">
<g transform="translate(30, 330)">
<line x1="20" x2="20" y1="0" y2="-320" stroke="black" stroke-width="2"/>
<line x1="20" x2="1000" y1="0" y2="0" stroke="black" stroke-width="2"/>
<line x1="20" x2="1000" y1="-150" y2="-150" stroke="black" opacity="0.5"
stroke-dasharray="8 4" stroke-width="1"/>
<text x="10" y="5" text-anchor="end">0%</text>
<text x="10" y="-145" text-anchor="end">50%</text>
<text x="10" y="-295" text-anchor="end">100%</text>
<xsl:apply-templates/>
</g>
</svg>
</xsl:template>
<xsl:template match="poem">
<xsl:variable name="totalWords" select="sum(count(verb|prep|noun|adv|adj|conj|inter|pron))"/>
<xsl:variable name="openValues" select="sum(count(@value='open'))"/>
<xsl:variable name="closedValues" select="sum(count(@value='closed'))"/>
<xsl:variable name="openPercent" select="$openValues div $totalWords"/>
<xsl:variable name="closedPercent" select="$closedValues div $totalWords"/>
<rect x="{25}" y="-{$closedPercent * 300}" stroke="black" stroke-width="1" fill="red" width="40" height="{$closedPercent * 300}"/>
<rect width="" height=""></rect>
</xsl:template>
</xsl:stylesheet>
the XPath in your "totalWords" variable isn't summing anything, so you're trying to divide by zero. Replace that path expression with a number, test to see if everything else works, then figure out what the path actually needs to be. Is it all descendants of stanzas? What's a better way to describe those tags without using union operators?
Thank you!
So after working for some time (with the help of a friend who is a CS major) I have a graph but when I run my XPath it isn't correctly counting what I need it to count and I don't know of a better way to do this.
<xsl:template match="poem">
<xsl:variable name="totalWords" select="count(//stanza/verb|noun|prep|adj|adv|conj)"/>
<xsl:variable name="openValues" select="count(@value='open')"/>
<xsl:variable name="closedValues" select="count(@value='closed')"/>
<xsl:variable name="openPercent" select="$openValues div $totalWords"/>
<xsl:variable name="closedPercent" select="$closedValues div $totalWords"/>
<rect x="{50}" y="-{$openPercent * 300}" stroke="black" stroke-width="1" fill="blue" width="40" height="{$openPercent * 300}"/>
<rect x="{115}" y="-{$closedPercent * 300}" stroke="black" stroke-width="1" fill="orange" width="40" height="{$closedPercent * 300}"/>
</xsl:template>
you want all the children of stanza EXCEPT <lb/>
I got it to work. Thank you @gabikeane !
Does anyone know why the following doesn't produce any visible rectangles?
`