<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tei="http://www.tei-c.org/ns/1.0" 
    exclude-result-prefixes="xs"
    version="2.0">
    <!--I added the xmlns:tei declaration to get the tei namespace, and it works now that I've added tei: prefix below -->
    <!--
    <xsl:output method="xml" indent="yes"/>
    -->
    
    
    <xsl:template match="/">
        <html>
            
            <head>
                <link rel="stylesheet" href="../css/place-list.css"/>
            </head>
            <body>
                <h2>Items marked as &lt;name&gt;</h2>
                <table xml:id="place-list" border="1">
                    <tr>
                        <td><h3>Term</h3></td>
                        <td><h3>Type</h3></td>
                        <td><h3>Subtype</h3></td>
                        <td><h3>Filename</h3></td>
                        <td><h3>Omeka URL</h3></td>
                    </tr>
       
                                <!-- <td><xsl:value-of select="document('jhs-195918-01-01.xml')//tei:text"/></td> this works-->
                                
                               <!-- <td><xsl:copy-of select="document('jhs-195918-01-01.xml')"/></td> this works -->
                                
                            
                                    
                                    
                                  <!-- this works  
                                    
                            <xsl:for-each select="document('jhs-195918-01-02.xml')//tei:name">
                                    <tr>
                                    <td>
                                    <xsl:value-of select="."/>
                                    </td>
                                    </tr>
                                    </xsl:for-each>
                                  
                                  -->
                    
                    <!-- this currently sorts within each individual file. I need to build entire list first across all files, and then sort? -->
                    
                    
                    
                    <xsl:for-each select="list/entry">
                        
                    <!--    <xsl:sort select="."/> -->
     
                        <xsl:variable name="filename" select="@name"/>
                        
                        <!-- this is working but some at beginning don't have value for ab yet -->
                        <xsl:variable name="omekaURL" select="document(string($filename))//tei:ab"/>
                        
                        <xsl:variable name="docTitle" select="document(string($filename))//tei:titleStmt/tei:title"/>

                        <!--this works to just select places -->
                        <xsl:for-each select="document(string($filename))//tei:name[@type='place']"> 
                        <!-- for now, select everything -->
                     <!--   <xsl:for-each select="document(string($filename))/tei:TEI/tei:text/tei:body//tei:name"> -->
                        <!--    <xsl:sort select="@type"/> -->
                       <!--  <xsl:sort select="@subtype"/> -->
                            <!-- this sorts them within each file.  or does nothing? -->
                    <!--    <xsl:sort select="."/> -->
                    
                            <!--    <xsl:sort select="tei:name"/>-->
                            <tr>
                                <td>                                  
                                    <xsl:copy-of select="."/>                                
                                </td>
                                <td>
                                    <type><xsl:value-of select="@type"/></type>
                                </td>
                                <td>
                                    <subtype><xsl:value-of select="@subtype"/></subtype>
                                </td>
                                <td>
                                    <!-- concat(<a href="https://unfdhi.org/violamuse-editions/content/, string($filename), ">)-->
                                    <filename><xsl:value-of select="$docTitle"/>
                                    </filename>
                                    <!--</a>-->
                                </td>
                                <td>
                                    <!-- concat(<a href="https://unfdhi.org/violamuse-editions/content/, string($filename), ">)-->
                                    <filename><xsl:value-of select="$filename"/>
                                    </filename>
                                    <!--</a>-->
                                </td>
                                <td>
                                    <!-- concat(<a href="https://unfdhi.org/violamuse-editions/content/, string($filename), ">)-->
                                    <filename><xsl:value-of select="$omekaURL"/>
                                    </filename>
                                    <!--</a>-->
                                </td>
                            </tr>
                        </xsl:for-each>
                    </xsl:for-each>
                
                    
                
                        
                     
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

 