Skip to content

Commit

Permalink
perspective fix, readme corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
E.Azer Koçulu committed Aug 14, 2010
1 parent 73b657b commit 872ffd6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Pure HTML&XSLT chess board viewing the context formatted in Forsyth–Edwards Notation.
Working Example: https://azer.github.com/fenviewer/initial.xml
Pure HTML&XSLT chess board getting its content in Forsyth–Edwards Notation.
Working Example: https://azer.github.com/chessboard/initial.xml
87 changes: 67 additions & 20 deletions template.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

<xsl:template name='square'>
<xsl:param name="identifier"></xsl:param>
<xsl:if test='contains("12345678rnbqkpRNBQKP",$identifier)'>
<div class="square">
<xsl:if test='not(contains("12345678",$identifier))'>
<xsl:call-template name="piece">
<xsl:with-param name="identifier" select="$identifier" />
</xsl:call-template>
</xsl:if>
</div>
</xsl:if>
<div class="square">
<xsl:if test='not($identifier="#")'>
<xsl:call-template name="piece">
<xsl:with-param name="identifier" select="$identifier" />
</xsl:call-template>
</xsl:if>
</div>
</xsl:template>

<xsl:template name='piece'>
Expand Down Expand Up @@ -47,53 +45,102 @@
</img>
</xsl:template>

<xsl:template name="list-content">
<xsl:template name="list">
<xsl:param name='content'></xsl:param>
<xsl:param name='rankCounter'>1</xsl:param>
<xsl:param name='fileCounter'>1</xsl:param>
<xsl:param name='rankIncrease'>1</xsl:param>

<xsl:call-template name='square'>
<xsl:with-param name="identifier" select='substring($content,$rankCounter*8-8+$fileCounter,1)' />
</xsl:call-template>

<xsl:if test='( $rankIncrease = -1 and $rankCounter&gt;1 or $fileCounter&lt;8 ) or ( $rankIncrease = 1 and $rankCounter&lt;8 or $fileCounter&lt;8 )'>
<xsl:choose>
<xsl:when test='$fileCounter=8'>
<xsl:call-template name='list'>
<xsl:with-param name="content" select='$content' />
<xsl:with-param name="rankIncrease" select='$rankIncrease' />
<xsl:with-param name="rankCounter" select='$rankCounter + $rankIncrease' />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name='list'>
<xsl:with-param name="content" select='$content' />
<xsl:with-param name="rankCounter" select='$rankCounter' />
<xsl:with-param name="rankIncrease" select='$rankIncrease' />
<xsl:with-param name="fileCounter" select='$fileCounter + 1' />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>

</xsl:template>


<xsl:template name="parse">
<xsl:param name="content">rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1</xsl:param>
<xsl:param name='parsedContent'></xsl:param>
<xsl:param name="squareCounter">1</xsl:param>
<xsl:param name="identifierCounter">1</xsl:param>
<xsl:param name="charCounter">1</xsl:param>
<xsl:variable name="identifier" select='substring($content,$charCounter,1)' />

<xsl:call-template name="square">
<xsl:with-param name="identifier" select="$identifier" />
</xsl:call-template>
<xsl:if test='string-length($parsedContent)=64'>
<xsl:if test='@perspective = "w"'>
<xsl:call-template name='list'>
<xsl:with-param name="content" select='$parsedContent' />
<xsl:with-param name="rankCounter" select='8' />
<xsl:with-param name="rankIncrease" select='-1' />
</xsl:call-template>
</xsl:if>
<xsl:if test='@perspective = "b"'>
<xsl:call-template name='list'>
<xsl:with-param name="content" select='$parsedContent' />
</xsl:call-template>
</xsl:if>
</xsl:if>

<xsl:if test='contains("12345678",$identifier)'>
<xsl:choose>
<xsl:when test="$squareCounter - $identifierCounter=$identifier - 1">
<xsl:call-template name="list-content">
<xsl:call-template name="parse">
<xsl:with-param name="squareCounter" select="$squareCounter + 1" />
<xsl:with-param name="identifierCounter" select="$identifierCounter + $identifier" />
<xsl:with-param name="charCounter" select="$charCounter + 1" />
<xsl:with-param name="content" select="$content" />
<xsl:with-param name="parsedContent" select='concat($parsedContent,"#")' />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="list-content">
<xsl:call-template name="parse">
<xsl:with-param name="squareCounter" select="$squareCounter + 1" />
<xsl:with-param name="identifierCounter" select="$identifierCounter" />
<xsl:with-param name="charCounter" select="$charCounter" />
<xsl:with-param name="content" select="$content" />
<xsl:with-param name="parsedContent" select='concat($parsedContent,"#")' />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>

<xsl:if test='contains("rnbqkpRNBQKP",$identifier)'>
<xsl:call-template name="list-content">
<xsl:with-param name="squareCounter" select="$squareCounter + 1" />
<xsl:call-template name="parse">
<xsl:with-param name="squareCounter" select="$squareCounter + 1" />
<xsl:with-param name="identifierCounter" select="$identifierCounter + 1" />
<xsl:with-param name="charCounter" select="$charCounter + 1" />
<xsl:with-param name="content" select="$content" />
<xsl:with-param name="parsedContent" select='concat($parsedContent,$identifier)' />
</xsl:call-template>
</xsl:if>

<xsl:if test='contains("/",$identifier)'>
<xsl:call-template name="list-content">
<xsl:call-template name="parse">
<xsl:with-param name="squareCounter" select="$squareCounter" />
<xsl:with-param name="identifierCounter" select="$identifierCounter" />
<xsl:with-param name="charCounter" select="$charCounter + 1" />
<xsl:with-param name="content" select="$content" />
<xsl:with-param name="parsedContent" select="$parsedContent" />
</xsl:call-template>
</xsl:if>

Expand All @@ -107,8 +154,8 @@
chessboard
perspective-<xsl:value-of select="@perspective" />
</xsl:attribute>
<xsl:call-template name="list-content">
<xsl:with-param name="content" select="/chessboard/fen" />
<xsl:call-template name="parse">
<xsl:with-param name="content" select="normalize-space(/chessboard/fen)" />
</xsl:call-template>
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions themes/default.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.chessboard { width:800px; height:800px; background:#ccc; }
.chessboard.perspective-w { -webkit-transform:rotate(180deg); -moz-transform:rotate(180deg); -o-transform:rotate(180deg); }
.chessboard.perspective-w .piece { -webkit-transform:rotate(180deg); -moz-transform:rotate(180deg); -o-transform:rotate(180deg) }

.chessboard .square { width:12.5%; height:12.5%; float:left; }
.chessboard .square .piece { width:100%; height:100%; }
Expand Down

0 comments on commit 872ffd6

Please sign in to comment.