newtfire / digitProjectDesign-Hub

shared repo for DIGIT 400: Digital Project Design class at Penn State Erie, The Behrend College
Creative Commons Zero v1.0 Universal
12 stars 2 forks source link

SVG Exercise 2 Help #29

Closed PiperBaron closed 3 years ago

PiperBaron commented 3 years ago

Hey, everyone!

I was wondering if anyone could help me finish up our second SVG exercise. I'm super close, but there's one thing tripping me up.

I'm at the stage where I'm writing in the lines between the circles. The lines seem to start in the right place, but they mostly end up pointing in random directions. I think the x2 values are correct, but my y2 values are all messed up, and I can't figure out why.

Here's my code:

<xsl:for-each select="//chapter">
                <xsl:variable name="Xpos" select="position() * $Xinterval"/>
                <xsl:variable name="Ypos" select="count(descendant::q[@sp='alice']) * $Ystretcher"/>
                <xsl:variable name="XposNext" select="(position() + 1) * $Xinterval"/>
                <xsl:variable name="YposNext" select="count(following-sibling::chapter/descendant::q[@sp='alice']) * $Ystretcher"/>

                <g id="Chap{position()}">
                    <circle cx="{$Xpos}" cy="{$Ypos}" r="5" fill="red"/>
                    <text x="{$Xpos}" y="10">Chapter <xsl:value-of select="@which"/></text>
                    <line x1="{$Xpos}" y1="{$Ypos}" x2="{$XposNext}" y2="{$YposNext}" stroke="black"/>
                </g>
</xsl:for-each>

For my XposNext variable, I just added 1 to the position, which seemed to work. For the YposNext, I've been trying to access the following sibling for each chapter, but it's not working the way I'm expecting it to. It almost seems like it's selecting every sibling after a given chapter, not the direct, following sibling, which is what I need.

Any help would be greatly appreciated!

ebeshero commented 3 years ago

@PiperBaron You've identified the problem--yes! It's getting you a count for ALL of the following-sibling::chapter elements instead of the very next following sibling. To get that one, realize it is just the first following sibling in the series. You just want a predicate to filter out JUST the very first following-sibling::chapter.

PiperBaron commented 3 years ago

@ebeshero

Ohhh, I got it! Adding that filter just fixed the whole thing.

<xsl:variable name="YposNext" select="count(following-sibling::chapter[1]/descendant::q[@sp='alice']) * $Ystretcher"/>

Funny how something so small and simple can make or break your code! :P