This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Muenchian keys ... plus a bit? - soln
- To: xsl-list at lists dot mulberrytech dot com
- Subject: RE: [xsl] Muenchian keys ... plus a bit? - soln
- From: DPawson at rnib dot org dot uk
- Date: Thu, 23 Aug 2001 12:31:36 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
After much circling, and a couple of diversions,
a solution. I initially had the 'alphabet' in the source
document. This is messy, but neater and easier than
holding it in the stylesheet as a variable, which makes
for a messy stylesheet.
If in the stylesheet as a namespaced list I couldn't figure
the context hopping.
Quite instructive.
Regards DaveP
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://mine/java.lang.String"
xmlns:saxon="http://icl.com/saxon"
version="1.0">
<xsl:script implements-prefix ="java" language="java"
src="java:java.lang.String"/>
<xsl:output method="html"/>
<xsl:key name="ebl" match="/idx/ent" use="substring(item,1,1)" />
<xsl:key name="entries" match="ent" use="item" />
<xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:template match="/">
<html>
<body bgcolor="#FFFFFF">
<!-- Create index -->
<p>
<xsl:call-template name="idx">
<xsl:with-param name="let" select="string($uc)"/>
</xsl:call-template>
</p>
<!-- add entries -->
<xsl:call-template name="tgt">
<xsl:with-param name="let" select="string($uc)"/>
</xsl:call-template>
</body>
</html>
</xsl:template>
<!-- Index named template -->
<xsl:template name="idx">
<xsl:param name="let"/>
<xsl:variable name="ent"
select="key('ebl', translate(substring($let,1,1),$uc,$lc))[1]/item"/>
<xsl:if test="$ent">
<a><xsl:attribute name="href">#<xsl:value-of
select="substring($let,1,1)"/></xsl:attribute>
<xsl:value-of select="substring($let,1,1)"/></a> 
</xsl:if>
<xsl:if test="string-length($let) > 1">
<xsl:call-template name="idx">
<xsl:with-param name="let" select="substring($let,2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="tgt">
<xsl:param name="let"/>
<xsl:variable name="ent"
select="key('ebl', translate(substring($let,1,1),$uc,$lc))[1]/item"/>
<xsl:if test="$ent">
<!-- Create anchor -->
<a><xsl:attribute name="name"><xsl:value-of
select="substring($let,1,1)"/></xsl:attribute>
<xsl:value-of select="substring($let,1,1)"/></a> 
<!-- OUtput content (if any)-->
<xsl:message><xsl:value-of
select="translate(substring($let,1,1),$uc,$lc) "/> </xsl:message>
<xsl:value-of select="$ent"/> 
<xsl:for-each select="key('entries',$ent)/pge">
<xsl:value-of select="."/><xsl:if
test="not(position()=last())">,</xsl:if>
</xsl:for-each>
<hr />
</xsl:if>
<!-- recurse if more -->
<xsl:if test="string-length($let) > 1">
<xsl:call-template name="tgt">
<xsl:with-param name="let" select="substring($let,2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
> -----Original Message-----
> From: DPawson@rnib.org.uk [mailto:DPawson@rnib.org.uk]
> Sent: 22 August 2001 08:50
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] Muenchian keys ... plus a bit?
>
>
> Given
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE idx [
> <!ELEMENT idx (ent+)>
> <!ELEMENT ent (item, pge+)>
> <!ELEMENT item (#PCDATA)>
> <!ELEMENT pge (#PCDATA)>
> <!ATTLIST pge key (t|f) 'f'>
>
>
> ]>
>
> <idx>
> <ent>
> <item>content</item>
> <pge key="f">98</pge>
> </ent>
> <ent>
> <item>content</item>
> <pge key="f">108</pge>
> <pge>110</pge>
> </ent>
> <ent>
> <item>another</item>
> <pge key="f">100</pge>
> </ent>
> <ent>
> <item>zero</item>
> <pge key="t">210</pge>
> </ent>
> </idx>
>
>
> And indexing DTD.
>
> I want to present it as
>
> A B C .... Z
> (each hotlinked to the start of that letter).
>
> Then
>
> A (the anchor)
>
> aardvark, page 1,67,79
> (say with page 67
> -------------------
> B
>
> bathtub, page 3,5,7
>
> ------------------
>
> Z
>
> zero, page 210
> (210 in bold, its the main entry)
> etc.
>
> Two pass solution, first sorting, to make data entry easy.
> Being lazy, I don't always remember that I've already made
> an entry for a particular element, so there are duplicates.
> the <item> is duplicated, but the page numbers are not,
> hence the 'remove duplicates' approach of keys only partially works.
> Hence the Muenchian plus (I think :-).
>
> Question, how to remove the duplicate entries without losing
> the page numbers associated with the duplicate?
>
> I found this quite an interesting stylesheet, till I couldn't
> figure out the key definitions/usage, then I was stopped.
>
> I have everything except the 'remove duplicates' bit.
>
> Any help appreciated.
>
> Regards daveP
-
NOTICE: The information contained in this email and any attachments is
confidential and may be legally privileged. If you are not the
intended recipient you are hereby notified that you must not use,
disclose, distribute, copy, print or rely on this email's content. If
you are not the intended recipient, please notify the sender
immediately and then delete the email and any attachments from your
system.
RNIB has made strenuous efforts to ensure that emails and any
attachments generated by its staff are free from viruses. However, it
cannot accept any responsibility for any viruses which are
transmitted. We therefore recommend you scan all attachments.
Please note that the statements and views expressed in this email
and any attachments are those of the author and do not necessarily
represent those of RNIB.
RNIB Registered Charity Number: 226227
Website: http://www.rnib.org.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list