<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml" />

    <xsl:param name="BaseURL" />
    
    <xsl:template match="/Gallery">
        <gallery>
            <!--album id="ww_gallery_1" title="gallery 1" description="artist woody woodill" lgPath="gallery_7/images/" tnPath="gallery_7/thumbnails/" tn="gallery_7/thumbnails/atn.jpg"-->
            <xsl:for-each select="Album">
                <album>
                    <xsl:attribute name="id">
                        <xsl:value-of select="GalleryAlbumID" />
                    </xsl:attribute>
                    <xsl:attribute name="title">
                        <xsl:value-of select="GalleryAlbumTitle" />
                    </xsl:attribute>
                    <xsl:attribute name="description">
                        <xsl:value-of select="GalleryAlbumDescription" />
                    </xsl:attribute>
                    <xsl:attribute name="lgPath">
                        <!--This is the base path to <img src=pic.jpg...-->
                        <xsl:value-of select="concat($BaseURL, replace(AlbumPiece[ImageUse='Display']/Path,'\\','/'),'/')" />
                    </xsl:attribute>
                    <xsl:attribute name="tnPath">
                        <!--thumbnail folder...-->
                        <xsl:value-of select="concat($BaseURL, replace(AlbumPiece[ImageUse='Thumbnail']/Path,'\\','/'),'/')" />
                    </xsl:attribute>
                    <xsl:attribute name="tn">
                        <!--thumbnail for the album...-->
                        <xsl:choose>
                            <xsl:when test="AlbumPiece[IsPrimary = 'true']/FileName != ''">
                                <xsl:value-of select="concat($BaseURL, replace(AlbumPiece[(ImageUse='Thumbnail') and (IsPrimary = 'true')]/Path,'\\','/'), '/', AlbumPiece[ImageUse = 'Thumbnail' and IsPrimary = 'true']/FileName)" />
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="concat($BaseURL, replace(AlbumPiece[ImageUse='Thumbnail']/Path,'\\','/'), '/', AlbumPiece[ImageUse='Thumbnail']/FileName)" />
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:for-each select="AlbumPiece[ImageUse='Display']">
                        <!--img src="206.jpg" caption="gallery 1: piece by artist woody woodill" link="javascript:MM_openBrWindow('large_7/206.html')" /-->
                        <img>
                            <xsl:attribute name="src">
                                <xsl:value-of select="FileName" />
                            </xsl:attribute>
                            <xsl:attribute name="caption">
                                <xsl:choose>
                                    <xsl:when test="GalleryPieceDescription != ''">
                                        <xsl:value-of select="GalleryPieceDescription" />
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="ancestor::Album/GalleryAlbumTitle" />
                                        <xsl:text>: piece by artist woody woodill</xsl:text>
                                        <!--<xsl:value-of select="ancestor::Album/GalleryAlbumDescription" />-->
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:attribute>
                            <xsl:apply-templates select="ImageSourceID" />
                            
                            <xsl:attribute name="debug">
                                <xsl:text>GalleryPieceID: </xsl:text>
                                <xsl:value-of select="GalleryPieceID" />
                                <xsl:text> ImageSourceID: </xsl:text>
                                <xsl:value-of select="ImageSourceID" />
                                <xsl:text> ImageSizeID: </xsl:text>
                                <xsl:value-of select="ImageSizeID" />
                                <xsl:text> IsPrimary: </xsl:text>
                                <xsl:value-of select="IsPrimary" />
                            </xsl:attribute>
                        </img>
                    </xsl:for-each>
                </album>
            </xsl:for-each>
        </gallery>
    </xsl:template>
    
    <xsl:template match="ImageSourceID">
        <xsl:attribute name="link">
            <xsl:value-of select="concat('javascript:openWindowForLargeGalleryPiece(''', $BaseURL, replace(ancestor::Album/AlbumPiece[ImageSourceID=current() and ImageUse='Full']/Path,'\\','/'), '/', ancestor::Album/AlbumPiece[ImageSourceID=current() and ImageUse='Full']/FileName, ''')')" />
        </xsl:attribute>
    </xsl:template>

</xsl:stylesheet>
