Subject: RE: Needing suggestions for better XSL logic
From: <Kevin.Weiss@xxxxxxx>
Date: Thu, 26 Oct 2006 09:55:24 -0400
|
Thanks for the replies! Unfortunately, I'm still having problems. I
tried applying a simple version of Mr. Gandhi's stylesheet that should
print just the ANSI characters:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="html" encoding="UTF-8" />
<xsl:template match="/resultset">
<html>
<body>
<xsl:for-each select="65 to 90">
<xsl:variable name="letter"
select="code-points-to-string(.)" />
<p><xsl:value-of select="$letter" /></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I receive the following error:
Expected token 'eof' found 'NAME'. 65 -->to <--90
I can't find much of anything on the web about this error. I'm testing
this by opening the XML file in IE6 (the file links to the stylesheet
with <?xml-stylesheet type="text/xsl" href="glossary.xsl"?>). Any help
is appreciated. Thanks again!
Kevin Weiss
-----Original Message-----
From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx]
Sent: Wednesday, October 25, 2006 1:21 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Needing suggestions for better XSL logic
(Learning from David's answer), I suggest the following XSLT 2.0
stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://dummy"
version="2.0">
<xsl:output method="html"/>
<xsl:template match="/resultset">
<xsl:variable name="here" select="." />
<html>
<head>
<title/>
</head>
<body>
<xsl:for-each select="65 to 90">
<xsl:variable name="letter" select="codepoints-to-string(.)"/>
<p><xsl:value-of select="$letter" /></p>
<xsl:variable name="htmlFragment"
select="my:getHtmlFragment($letter, $here)" />
<xsl:copy-of select="$htmlFragment" />
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:function name="my:getHtmlFragment" as="node()*">
<xsl:param name="letter" as="xs:string"/>
<xsl:param name="here" as="element()"/>
<ul>
<xsl:for-each select="$here/term[starts-with(termname, $letter) or
starts-with(termname, lower-case($letter))]">
<li><xsl:value-of select="termname" /> (<xsl:value-of
select="termattrs/termdef" />)</li>
</xsl:for-each>
</ul>
</xsl:function>
</xsl:stylesheet>
On 10/25/06, Kevin.Weiss@xxxxxxx <Kevin.Weiss@xxxxxxx> wrote:
> Hi all,
>
> I'm trying to find a better alternative to our current test XSL
> template. Currently, we have the following XML file structure
> (extremely simplified from the original):
>
> <resultset>
> <term>
> <termname>First Term</termname>
> <termattrs>
> <termdef>This is the firstterm description.</termdef>
> </termattrs>
> </term>
> <term>
> <termname>Second Term</termname>
> <termattrs>
> <termdef>This is the second term description.</termdef>
> </termattrs>
> </term>
> </resultset>
>
> We're trying build a glossary of the terms listed in alphabetical
order.
> In other words, after the translation, viewing the XML (in IE) should
> produce an output similar to the following:
>
> A
> B
> ...
> F
> First Term (This is the first term description.) ...
> S
> Second Term (This is the second term description.) ...
> Z
>
> Unfortunately, our current XSL logic involves an <xsl:for-each> loop
> which tests whether the first letter of <termname> begins with a
letter.
> However, this is done for *each* letter, so we have duplicate code,
> i.e.:
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> ...
> <p>A</p>
> <xsl:template match="/resultset">
> <xsl:for-each select="term">
> <xsl:if test="starts-with(termname, 'A') or
> starts-with(termname, 'a')">
> <xsl:value-of select="termname" />
> <xsl:value-of select="termattrs/termdef" />
> </xsl:if>
> </xsl:for-each>
>
> <p>B</p>
> <xsl:template match="/resultset">
> <xsl:for-each select="term">
> <xsl:if test="starts-with(termname, 'B') or
> starts-with(termname, 'b')">
> <xsl:value-of select="termname" />
> <xsl:value-of select="termattrs/termdef" />
> </xsl:if>
> </xsl:for-each>
> ...
> </xsl:template>
> </xsl:stylesheet>
>
> Is there a better method than using multiple <xsl:for-each> loops?
> We've looked into other options (e.g. xsl:for-each-group, using
> multiple apply-templates), but nothing produces our desired output. My
> brain is mush right now, so any suggestions are greatly appreciated.
> If there's anything else you need from me, please let me know. Thanks
in advance!
>
> Kevin Weiss
--
Regards,
Mukul Gandhi
|