Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A-Z list links (qid=1328351 cont.) 1

Status
Not open for further replies.

meandering

Technical User
Oct 9, 2012
13
CH

Hi

After a long search I found thread 1328351 but it's closed. As k5tm is still active here, I hope he sees this or maybe somebody else can reply.

I integrated the last reply (7 Feb 07 11:28) into my xslt and get it to run without complaints. As I am a beginner I now should find out which part of his code to replace with my field name.

"My" original sort select was:
<xsl:sort select="translate(normalize-space(translation/translations/entry/value),'abcdefghijklmnopqrstuvwxyzäöüéèàç','ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>

But the sort still works when I shorten it to
<xsl:sort select="translation/translations/entry/value"/>
which is what the name field is called in the XML file.

It's normal text, A-Z, what I would like to do is insert a jump navigation so I can navigate to a certain letter in the alphabet, which would be the first letter of translation/translations/entry/value.

---

I will copy k5tm's reply below - my question is: where do I have to replace his "name" with my "translation/translations/entry/value"?

If there is a simpler solution by now I'm not at all against it!

Thank you :)
 
Thread 1328351, k5tm, 7 Feb 07 11:28

Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet  xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
<xsl:output method="html"/>

<xsl:key name="initialChar" match="resource" use="translate(substring(name,1,1),
                                                     'abcdefghijklmnopqrstuvwxyz',
                                                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />

<xsl:template match="/">
    <html>
    <body>
    <!-- iterate over all the unique initial letter values -->
    <xsl:for-each select="//resource[generate-id(.)=generate-id(key('initialChar', 
                                                                  translate(substring(name,1,1),
                                                                'abcdefghijklmnopqrstuvwxyz',
                                                                'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))[1])]">
        <!-- sort the nodes for this initial letter value by name -->
        <xsl:sort select="name"/>
          <xsl:variable name="myChar" select="translate(substring(name,1,1),
                                                      'abcdefghijklmnopqrstuvwxyz',
                                                         'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
        <!-- output the links -->
        <xsl:call-template name="genLinks"/>
        <xsl:element name="a"><xsl:attribute name="name"><xsl:value-of select="string($myChar)"/></xsl:attribute></xsl:element>
        <!-- output all the nodes having this intial letter value -->
        <xsl:for-each select="key('initialChar',$myChar)">
            <xsl:sort select="name"/>
            <h2><xsl:value-of select="name"/></h2>
            <h3><xsl:value-of select="description"/></h3>
        </xsl:for-each>
      </xsl:for-each>
        <!-- output the final links -->
        <xsl:call-template name="genLinks"/>
    </body>
    </html>

</xsl:template>

<xsl:template name="genLinks">
        <span style="letter-spacing:7px; font-size=12pt">
        <center>
        <!-- The for-each will iterate exactly once for each unique initial letter. -->
        <xsl:for-each select="//resource[generate-id(.)=generate-id(key('initialChar', 
                                                                       translate(substring(name,1,1),
                                                                    'abcdefghijklmnopqrstuvwxyz',
                                                                    'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))[1])]">
            <xsl:sort select="name"/>
            <xsl:variable name="myLinkChar" select="translate(substring(name,1,1),
                                            'abcdefghijklmnopqrstuvwxyz',
                                            'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
            <a><xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="$myLinkChar"/></xsl:attribute>
               <xsl:value-of select="$myLinkChar"/></a>
               <xsl:if test="position()!=last()"><xsl:text>-</xsl:text></xsl:if>
        </xsl:for-each>
        </center>
        </span>
</xsl:template>

</xsl:stylesheet>
 
I am still here. Not enough time to study this right now, but will try to come back to this...

Tom Morrison
Micro Focus
 
Thank you. No hurry - it's just the closest I got so far. I would tell you here if I solved it some other way.

"But the sort still works when I shorten it..." is not true, it has to be normalized to sort correctly.

This is the output without the A-Z navigation: swissbib.ch/libraries.
 
Ok, I would need to see a small sample of your XML input document. (I presume it is used to produce the output seen at your link.) It would also be good for you to post your existing XSLT.

And I am slightly confused about exactly what you are asking. If you are asking about the navigation links, the following code lines are used to create the link line, followed by an anchor tag for the letter being started:
Code:
        <!-- output the links -->
        <xsl:call-template name="genLinks"/>[highlight #73D216]<!--  this template generates the line[/highlight] 
                                            [highlight #73D216]containing the links to all the letters -->[/highlight]

        [highlight #73D216]<!-- the following line creates the anchor tag before the entries beginning with the letter contained in $myChar -->[/highlight]
        <xsl:element name="a"><xsl:attribute name="name"><xsl:value-of select="string($myChar)"/></xsl:attribute></xsl:element>

Tom Morrison
Micro Focus
 
> And I am slightly confused about exactly what you are asking.

Which part of your code I have to replace with my sort select. I'll copy the XML + XSLT below, but I'm out of office until next Thursday and offline from tomorrow until Wednesday.

Thank you for taking the time to look into this :)

 
Output

XML:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<libraryconfiguration>
 <libraries>
        <library>
            <addressURL>[URL unfurl="true"]http://www.indologie.uzh.ch/access.html</addressURL>[/URL]
            <adminDatabase>UZH50</adminDatabase>
            <designator>true</designator>
            <favorite>true</favorite>
            <favoriteQueryString>9902="UINDO"</favoriteQueryString>
            <id>1863</id>
            <institutionURL> </institutionURL>
            <libraryGroupIdentifier>UZH01</libraryGroupIdentifier>
            <libraryIdentifier>UINDO</libraryIdentifier>
            <libraryIdentifierMatcher> </libraryIdentifierMatcher>
            <name>UINDO</name>
            <reroSubGroup> </reroSubGroup>
            <road>Rämistr. 68</road>
            <sort>0</sort>
            <town>Zürich</town>
            <translation>
                <designator>TP_PARAMETER_[1863,0]</designator>
                <groupId>655</groupId>
                <translations>
                    <entry>
                        <key>de</key>
                        <value>Uni Zürich - Asien-Orient Institute - Indologische Bibliothek</value>
                    </entry>
                    <entry>
                        <key>it</key>
                        <value>Uni Zürich - Asien-Orient Institute - Indologische Bibliothek</value>
                    </entry>
                    <entry>
                        <key>fr</key>
                        <value>Uni Zürich - Asien-Orient Institute - Indologische Bibliothek</value>
                    </entry>
                    <entry>
                        <key>en</key>
                        <value>Uni Zürich - Asien-Orient Institute - Indologische Bibliothek</value>
                    </entry>
                    <entry>
                        <key>nl</key>
                        <value></value>
                    </entry>
                </translations>
            </translation>
            <treeLeaf>
                <rootId>3</rootId>
                <sort>0</sort>
                <treeNodeId>79</treeNodeId>
                <valueId>1863</valueId>
            </treeLeaf>
            <type>2</type>
            <url>[URL unfurl="true"]http://biblio.unizh.ch/F?func=item-global&amp;doc_library=UZH01&amp;doc_number=&lt;&lt;RecordID&gt;&gt;&amp;sub_library=UINDO</url>[/URL]
            <zipCode>8001</zipCode>
        </library>
        <library>
            <addressURL>[URL unfurl="true"]http://www.ville-fribourg.ch/vfr/fr/pub/officielle/admin_generale/archives.htm</addressURL>[/URL]
            <adminDatabase> </adminDatabase>
            <designator>true</designator>
            <favorite>true</favorite>
            <favoriteQueryString>9902="R1089"</favoriteQueryString>
            <id>1078</id>
            <institutionURL> </institutionURL>
            <libraryGroupIdentifier>RERO</libraryGroupIdentifier>
            <libraryIdentifier>10890000</libraryIdentifier>
            <libraryIdentifierMatcher>R1089</libraryIdentifierMatcher>
            <name>10890000</name>
            <reroSubGroup>R1</reroSubGroup>
            <road>Rue des Chanoines 1</road>
            <sort>0</sort>
            <town>Fribourg</town>
            <translation>
                <designator>TP_PARAMETER_[1078,0]</designator>
                <groupId>655</groupId>
                <translations>
                    <entry>
                        <key>de</key>
                        <value>Archives de la Ville de Fribourg</value>
                    </entry>
                    <entry>
                        <key>it</key>
                        <value>Archives de la Ville de Fribourg</value>
                    </entry>
                    <entry>
                        <key>fr</key>
                        <value>Archives de la Ville de Fribourg</value>
                    </entry>
                    <entry>
                        <key>en</key>
                        <value>Archives de la Ville de Fribourg</value>
                    </entry>
                    <entry>
                        <key>nl</key>
                        <value>Archives de la Ville de Fribourg</value>
                    </entry>
                </translations>
            </translation>
            <treeLeaf>
                <rootId>3</rootId>
                <sort>28</sort>
                <treeNodeId>76</treeNodeId>
                <valueId>1078</valueId>
            </treeLeaf>
            <type>2</type>
            <url>[URL unfurl="true"]http://opac.rero.ch/gateway?beginsrch=1&amp;lng=&lt;&lt;Language&gt;&gt;&amp;inst=&lt;&lt;Institution&gt;&gt;&amp;search=KEYWORD&amp;function=INITREQ&amp;t1=&lt;&lt;RecordID&gt;&gt;&amp;u1=12101&amp;floc=&lt;&lt;SubLibraryFilter&gt;&gt;&amp;fltset=submsn</url>[/URL]
            <zipCode>1701</zipCode>
        </library>
        <library>
            <addressURL>[URL unfurl="true"]http://www.musees-neuchatelois.ch/lieux/la-chaux-de-fonds/musee-international-dhorlogerie</addressURL>[/URL]
            <adminDatabase> </adminDatabase>
            <designator>true</designator>
            <favorite>true</favorite>
            <favoriteQueryString>9902="R31083"</favoriteQueryString>
            <id>1820</id>
            <institutionURL> </institutionURL>
            <libraryGroupIdentifier>RERO</libraryGroupIdentifier>
            <libraryIdentifier>310830000</libraryIdentifier>
            <libraryIdentifierMatcher>R31083</libraryIdentifierMatcher>
            <name>310830000</name>
            <reroSubGroup>R31</reroSubGroup>
            <road>Rue des Musées 29</road>
            <sort>568</sort>
            <town>La Chaux-de-Fonds</town>
            <translation>
                <designator>TP_PARAMETER_[1820,0]</designator>
                <groupId>655</groupId>
                <translations>
                    <entry>
                        <key>de</key>
                        <value>Musée international de l'horlogerie, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>it</key>
                        <value>Musée international de l'horlogerie, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>fr</key>
                        <value>Musée international de l'horlogerie, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>en</key>
                        <value>Musée international de l'horlogerie, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>nl</key>
                        <value>Musée international de l'horlogerie, La Chaux-de-Fonds</value>
                    </entry>
                </translations>
            </translation>
            <treeLeaf>
                <rootId>3</rootId>
                <sort>246</sort>
                <treeNodeId>76</treeNodeId>
                <valueId>1820</valueId>
            </treeLeaf>
            <type>2</type>
            <url>[URL unfurl="true"]http://opac.rero.ch/gateway?beginsrch=1&amp;lng=&lt;&lt;Language&gt;&gt;&amp;inst=&lt;&lt;Institution&gt;&gt;&amp;search=KEYWORD&amp;function=INITREQ&amp;t1=&lt;&lt;RecordID&gt;&gt;&amp;u1=12101&amp;floc=&lt;&lt;SubLibraryFilter&gt;&gt;&amp;fltset=submsn</url>[/URL]
            <zipCode>2300</zipCode>
        </library>
        <library>
            <addressURL>[URL unfurl="true"]http://www.musees-neuchatelois.ch/lieux/la-chaux-de-fonds/musee-dhistoire-naturelle</addressURL>[/URL]
            <adminDatabase> </adminDatabase>
            <designator>true</designator>
            <favorite>true</favorite>
            <favoriteQueryString>9902="R31084"</favoriteQueryString>
            <id>1521</id>
            <institutionURL> </institutionURL>
            <libraryGroupIdentifier>RERO</libraryGroupIdentifier>
            <libraryIdentifier>310840000</libraryIdentifier>
            <libraryIdentifierMatcher>R31084</libraryIdentifierMatcher>
            <name>310840000</name>
            <reroSubGroup>R31</reroSubGroup>
            <road>Avenue Léopold-Robert 63</road>
            <sort>569</sort>
            <town>La Chaux-de-Fonds</town>
            <translation>
                <designator>TP_PARAMETER_[1521,0]</designator>
                <groupId>655</groupId>
                <translations>
                    <entry>
                        <key>de</key>
                        <value>Musée d'histoire naturelle, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>it</key>
                        <value>Musée d'histoire naturelle, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>fr</key>
                        <value>Musée d'histoire naturelle, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>en</key>
                        <value>Musée d'histoire naturelle, La Chaux-de-Fonds</value>
                    </entry>
                    <entry>
                        <key>nl</key>
                        <value>Musée d'histoire naturelle, La Chaux-de-Fonds</value>
                    </entry>
                </translations>
            </translation>
            <treeLeaf>
                <rootId>3</rootId>
                <sort>103</sort>
                <treeNodeId>76</treeNodeId>
                <valueId>1521</valueId>
            </treeLeaf>
            <type>2</type>
            <url>[URL unfurl="true"]http://opac.rero.ch/gateway?beginsrch=1&amp;lng=&lt;&lt;Language&gt;&gt;&amp;inst=&lt;&lt;Institution&gt;&gt;&amp;search=KEYWORD&amp;function=INITREQ&amp;t1=&lt;&lt;RecordID&gt;&gt;&amp;u1=12101&amp;floc=&lt;&lt;SubLibraryFilter&gt;&gt;&amp;fltset=submsn</url>[/URL]
            <zipCode>2300</zipCode>
        </library>
 <library>
            <addressURL>[URL unfurl="true"]http://www.infodoc-radix.ch/</addressURL>[/URL]
            <adminDatabase>EAD50</adminDatabase>
            <designator>true</designator>
            <favorite>true</favorite>
            <favoriteQueryString>9902="E88"</favoriteQueryString>
            <id>1175</id>
            <institutionURL> </institutionURL>
            <libraryGroupIdentifier>EBI01</libraryGroupIdentifier>
            <libraryIdentifier>E88</libraryIdentifier>
            <libraryIdentifierMatcher> </libraryIdentifierMatcher>
            <name>E88</name>
            <reroSubGroup> </reroSubGroup>
            <road>Stampfenbachstrasse 161</road>
            <sort>427</sort>
            <town>Zürich</town>
            <translation>
                <designator>TP_PARAMETER_[1175,0]</designator>
                <groupId>655</groupId>
                <translations>
                    <entry>
                        <key>de</key>
                        <value>infoDoc RADIX, Zürich</value>
                    </entry>
                    <entry>
                        <key>it</key>
                        <value>infoDoc RADIX, Zürich</value>
                    </entry>
                    <entry>
                        <key>fr</key>
                        <value>infoDoc RADIX, Zürich</value>
                    </entry>
                    <entry>
                        <key>en</key>
                        <value>infoDoc RADIX, Zürich</value>
                    </entry>
                    <entry>
                        <key>nl</key>
                        <value>infoDoc RADIX, Zürich</value>
                    </entry>
                </translations>
            </translation>
            <treeLeaf>
                <rootId>3</rootId>
                <sort>21</sort>
                <treeNodeId>75</treeNodeId>
                <valueId>1175</valueId>
            </treeLeaf>
            <type>2</type>
            <url>[URL unfurl="true"]http://opac.nebis.ch/F?func=item-global&amp;doc_library=EBI01&amp;doc_number=&lt;&lt;RecordID&gt;&gt;&amp;sub_library=E88</url>[/URL]
            <zipCode>8006</zipCode>
        </library>
    </libraries>
</libraryconfiguration>
 
XSL:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
    <xsl:output method="html" encoding="utf-8" indent="yes" />
    <xsl:param name="datestring" />

    <xsl:template match="/">
    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html></xsl:text>
        <html lang="de">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <title>Bibliotheken in swissbib</title>
                <link href="libstyle.css" rel="stylesheet" />
            </head> 
        <body>
        <div class="full_wrapper">
            
        <div class="title_wrapper">
               <h1 class="title">Bibliotheken in <xsl:element name="a"><xsl:attribute name="href">..</xsl:attribute>swissbib
                 </xsl:element></h1>
            
            <p>
                <xsl:if test="$datestring != ''">
                    <xsl:value-of select="concat('Stand: ',$datestring)"/>
                </xsl:if>
            </p>
            
              <p>  <xsl:element name="a">
                <xsl:attribute name="href">codelist.html</xsl:attribute>
                nach Codes sortieren
            </xsl:element>
            </p>
            
        </div>
            
        <div class="list_wrapper">
            <xsl:for-each select="//library">
           <xsl:sort select="translate(normalize-space(translation/translations/entry/value),'abcdefghijklmnopqrstuvwxyzäöüéèàç','ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>
                <div class="library">
                    
                <span class="libname">
                        <xsl:value-of select="normalize-space(translation/translations/entry/value)"/>
                    </span>
                    
                          <span class="rowtitle"><br /> </span>
                    <span class="address"><xsl:value-of select="translate(road,'&quot;','')"/></span>
                    <span class="rowtitle">, </span>
                    <span class="rowvontent">
                        <xsl:value-of select="zipCode"/><xsl:text> </xsl:text><xsl:value-of select="town" />
                    </span>
                    <span class="rowtitle"><br /></span>
                    
                  
                    <span class="bibinfo">
                        <xsl:if test="normalize-space(addressURL) != ''">
                            <xsl:element name="a">
                                <xsl:attribute name="href"><xsl:value-of select="normalize-space(addressURL)"/></xsl:attribute>
                                Bibliotheksinfo
                                <xsl:choose>
                                    <xsl:when test="libraryIdentifierMatcher != ' '">
                                        <xsl:value-of select="libraryIdentifierMatcher"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="name"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:element>
                        </xsl:if>
                    </span>
                    
                    <span class="rowtitle"><br /></span>
             
                    <span class="bibinfo">
                         <xsl:element name="a">
                                <xsl:choose>
                                    <xsl:when test="libraryIdentifierMatcher != ' '">
                                <xsl:element name="a"><xsl:attribute name="href">[URL unfurl="true"]http://www.swissbib.ch/TouchPoint/start.do?Query=1805="<xsl:value-of[/URL] select="libraryIdentifierMatcher"/>"</xsl:attribute>
                                            Bestand
                                        </xsl:element>
                                      </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:element name="a"><xsl:attribute name="href">[URL unfurl="true"]http://www.swissbib.ch/TouchPoint/start.do?Query=1805="<xsl:value-of[/URL] select="name"/>"</xsl:attribute>
                                            Bestand
                                        </xsl:element>               
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:element>
                    </span>
                </div>
            </xsl:for-each>
        </div>
    </div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
ps: the XSLT has a part <librarygroups> </librarygroups> before <libraries> </libraries>, but that's not used in my output.
 
and the css. the fonts weren't my idea ;)

Code:
 .full_wrapper {
	font-size: 80%;
	font-family:Arial, Helvetica, sans-serif;
	color:#494E59;
	word-wrap:break-word; 
}
  
 
  h1, h2, h3, h4, h5, h6 {
	font-family: "Times New Roman", Times, serif; 
	font-weight:bold;
	color:#2F333C;
}

  a {
	text-decoration:none;
	color:#1e9e00;
        }

 a:hover {
       	background-color:#D4F2CE;
	color:#0f5200;
	}

 a:visited {
	text-decoration:none;
	color:#146b00;
}

     
     .title_wrapper { 
       padding-top:0.3em;
       padding-left:1.5em;         
    }
    
      .list_wrapper { 
       padding-left:2.5em;  
       padding-bottom:1.5em;  
          }
    
     .library { 
       padding-top:1em;
       padding-right:0.3em;
          }
    
    .code { 
      padding-right:1em;
              }
    
    .libname { 
       font-weight:bold;
      padding-top:0.5em;
                   }
    
    .rowtitle { 
        padding-top:1em;
     }
    .rowcontent  { 
       padding-top:1em;
          } 
    
     .address { 
       padding-left:2em;
         }      
    
    .bibinfo { 
       padding-left:2em;
         }
 
Ok, I have had a look at your posts.

Yor XSLT has exactly one sort in it, so lets look at it.
Code:
            <xsl:for-each select="//library">
           <xsl:sort select="translate(normalize-space(translation/translations/entry/value),'abcdefghijklmnopqrstuvwxyzäöüéèàç','ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>

The xsl:for-each is going to iterate over the set of <library> nodes. The problem you may be having is that there are multiple translation/translations/entry/value nodes subordinate to each <library> node. Which one do you want to use for determining the sort order? Perhaps you would like to use the one whose language is 'de' rather than the first <value>, in which case you might want to use an XPath expression such as:
Code:
 translation/translations/entry[key='de']/value

Or maybe I am still not understanding what you are asking... [ponder] What in particular is wrong with your output?

Tom Morrison
Micro Focus
 
Nothing wrong with my output as it is, but I would like to introduce an jump navigation (is that the term?), so that I could jump directly to the names that begin with the letter U, for example, instead of having to scroll down: example.

I thought this was what thread 1328351 was solving but maybe I got that wrong?
 
You are correct, that is what that thread (and therefore this thread) is about.

And I understand now what I need to show you. Unfortunately, Thursday is my busiest day, especially in the morning (USA time).

I will return - probably today - with your solution.

Tom Morrison
Micro Focus
 
Here is a solution, which you should study and if not clear to you, ask questions.

I moved the formatting of an individual library into a called template, so that the link generation logic is more obvious.

I would suggest also that you use the xsl:eek:utput mechanism for output of the DOCTYPE declaration. I have chosen HTML 4.01 strict for the DOCTYPE; adjust as you see fit.

My technique outputs navigation links only for those letters that actually appear in the data. If you want a list of all letters, then a slightly different technique will be needed, and you need to decide whether there will be href values for all the letters, or whether only those letters that exist in the data will have href values.

Let me know how this works for you...

Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
    <xsl:output method="html" encoding="utf-8" indent="yes" doctype-system="[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd"[/URL] doctype-public="-//W3C//DTD HTML 4.01//EN"/>

    <xsl:param name="datestring" />

	<xsl:key name="libFirstChar" match="library" 
	                             use="translate(substring(normalize-space(translation/translations/entry/value[1]),1,1),
								                'abcdefghijklmnopqrstuvwxyzäöüéèàç',
									            'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>

    <xsl:template match="/">
        <html lang="de">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <title>Bibliotheken in swissbib</title>
                <link href="libstyle.css" rel="stylesheet" />
            </head> 
        <body>
        <div class="full_wrapper">
            
        <div class="title_wrapper">
               <h1 class="title">Bibliotheken in <xsl:element name="a"><xsl:attribute name="href">..</xsl:attribute>swissbib
                 </xsl:element></h1>
            
            <p>
                <xsl:if test="$datestring != ''">
                    <xsl:value-of select="concat('Stand: ',$datestring)"/>
                </xsl:if>
            </p>
            
              <p>  <xsl:element name="a">
                <xsl:attribute name="href">codelist.html</xsl:attribute>
                nach Codes sortieren
            </xsl:element>
            </p>
            
        </div>
            
        <div class="list_wrapper">
		   <!-- iterate over the first node for each starting character -->
		   <xsl:for-each select="//library[generate-id(.)=generate-id(key('libFirstChar', 
                                                                          translate(substring(normalize-space(translation/translations/entry/value[1]),1,1),
			                                                                        'abcdefghijklmnopqrstuvwxyzäöüéèàç',
                                                                                    'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC'))[1])]">
		   <xsl:sort select="translate(substring(normalize-space(translation/translations/entry/value[1]),1,1),
			                          'abcdefghijklmnopqrstuvwxyzäöüéèàç',
                                      'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>
           <!-- we are now in the context of a <library> node -->
           <xsl:variable name="myFirstChar" select="translate(substring(normalize-space(translation/translations/entry/value[1]),1,1),
                                                              'abcdefghijklmnopqrstuvwxyzäöüéèàç',
                                                              'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>

           <!-- output the links -->
           <xsl:call-template name="genLinks"/>
           <xsl:element name="a"><xsl:attribute name="name"><xsl:value-of select="string($myFirstChar)"/></xsl:attribute></xsl:element>
           <!-- Now iterate over all the <library> nodes that start with the same character sort value -->
		   <xsl:for-each select="key('libFirstChar',$myFirstChar)">
		   <!-- sort all the <library> nodes in this result set by their full <value> (we know they all start with the same first letter) -->
               <xsl:sort select="translate(normalize-space(translation/translations/entry/value),
                                           'abcdefghijklmnopqrstuvwxyzäöüéèàç',
                                           'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>
                   <xsl:call-template name="outputLibrary"/>
               </xsl:for-each>
           </xsl:for-each>
           <xsl:call-template name="genLinks"/>
        </div>
    </div>
</body>
</html>
</xsl:template>

<xsl:template name="genLinks">
        <span>
        <!-- The for-each will iterate exactly once for each unique initial letter. -->
        <xsl:for-each select="//library[generate-id(.)=generate-id(key('libFirstChar', 
                                                                          translate(substring(normalize-space(translation/translations/entry/value[1]),1,1),
			                                                                        'abcdefghijklmnopqrstuvwxyzäöüéèàç',
                                                                                    'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC'))[1])]">
            <xsl:sort select="translate(normalize-space(translation/translations/entry/value),
                                           'abcdefghijklmnopqrstuvwxyzäöüéèàç',
                                           'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>
            <xsl:variable name="myLinkChar" select="translate(substring(normalize-space(translation/translations/entry/value[1]),1,1),
                                                              'abcdefghijklmnopqrstuvwxyzäöüéèàç',
                                                              'ABCDEFGHIJKLMNOPQRSTUVWXYZAOUEEAC')"/>

            <a><xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="$myLinkChar"/></xsl:attribute>
               <xsl:value-of select="$myLinkChar"/></a>
               <xsl:if test="position()!=last()"><xsl:text>-</xsl:text></xsl:if>
        </xsl:for-each>
        </span>
</xsl:template>

<xsl:template name="outputLibrary">
                <div class="library">
                    
                <span class="libname">
                        <xsl:value-of select="normalize-space(translation/translations/entry/value)"/>
                    </span>
                    
                          <span class="rowtitle"><br /> </span>
                    <span class="address"><xsl:value-of select="translate(road,'&quot;','')"/></span>
                    <span class="rowtitle">, </span>
                    <span class="rowvontent">
                        <xsl:value-of select="zipCode"/><xsl:text> </xsl:text><xsl:value-of select="town" />
                    </span>
                    <span class="rowtitle"><br /></span>
                    
                  
                    <span class="bibinfo">
                        <xsl:if test="normalize-space(addressURL) != ''">
                            <xsl:element name="a">
                                <xsl:attribute name="href"><xsl:value-of select="normalize-space(addressURL)"/></xsl:attribute>
                                Bibliotheksinfo
                                <xsl:choose>
                                    <xsl:when test="libraryIdentifierMatcher != ' '">
                                        <xsl:value-of select="libraryIdentifierMatcher"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="name"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:element>
                        </xsl:if>
                    </span>
                    
                    <span class="rowtitle"><br /></span>
             
                    <span class="bibinfo">
                         <xsl:element name="a">
                                <xsl:choose>
                                    <xsl:when test="libraryIdentifierMatcher != ' '">
                                <xsl:element name="a"><xsl:attribute name="href">[URL unfurl="true"]http://www.swissbib.ch/TouchPoint/start.do?Query=1805="<xsl:value-of[/URL] select="libraryIdentifierMatcher"/>"</xsl:attribute>
                                            Bestand
                                        </xsl:element>
                                      </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:element name="a"><xsl:attribute name="href">[URL unfurl="true"]http://www.swissbib.ch/TouchPoint/start.do?Query=1805="<xsl:value-of[/URL] select="name"/>"</xsl:attribute>
                                            Bestand
                                        </xsl:element>               
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:element>
                    </span>
                </div>
</xsl:template>

</xsl:stylesheet>

Tom Morrison
Micro Focus
 
It works! :-D

Copying the code here had turned ..."translate(road,'&quot;','')" to ..."translate(road,'"','')"

but I can't see a way to edit a post.

I added a <br /> after <xsl:template name="genLinks">, now it looks great. Will be online soon.

I think all the keywords are covered, so others also have a chance of finding this.

Thank you again, this is exactly what I was looking for.
 
Yes I had the same problem with that same line when I copied your code into my XSLT debugger. It was correct going into the post. Such is the problem of trying to process XML through a complex system. I am on the 'advisory board' for Tek-Tips, so I will report this problem to the technical guys.

And, by the way, welcome to Tek-Tips!

Tom Morrison
Micro Focus
 
It looks like you can code an:
[tt]&amp;quot;[/tt]
inside the code box.

Here is an attempt:
XML:
<anelement attrib="&amp;quot;"/>

It works on the preview. Pressing Submit Post button...

Tom Morrison
Micro Focus
 
> welcome
Thank you. I'm glad i found it.

> I am on the 'advisory board'
Could you advise them to introduce an edit button?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top