----- Original Message ----
From: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
Subject: RE: [xsl] grouping, xslt 2.0
Message-ID: <008901c775c9$9231ec10$6401a8c0(_at_)turtle>
In an XSLT pattern, current() refers to the node you are trying to match. So
the pattern
group-starting-with="*[name() = translate(name(current()),'1234','2345')]">
is wrong. Try assigning the result of the translate() to a variable first.
Thanks. (The hint in XSLT 2.0, 3Ed, p298 is wrong then).
Using
<xsl:template match="*[starts-with(name(),'h')]">
<xsl:variable name="tag" select="translate(name(current()),'1234','2345')"/>
<xsl:message>
Match on <xsl:value-of select="name()"/>
Population is <xsl:value-of select="count(current-group())"/>
next is <xsl:value-of select="$tag"/>
</xsl:message>
<section level="{substring-after(name(),'h')}">
<head><xsl:apply-templates/></head>
<xsl:for-each-group select="current-group() except ."
group-starting-with="*[name() = $tag]">
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
</section>
</xsl:template>
Still doesn't hack it though.
It seems to handle the lower levels,
but not something like
h3
h3
h2
I.e. 'rising' levels which should be legitimate in the input I'm using.
I'll try some stuff from XSLT 1.0
JJ
-----Original Message-----
From: john jacks [mailto:john(_dot_)jacks(_at_)yahoo(_dot_)co(_dot_)uk]
Sent: 03 April 2007 08:49
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] grouping, xslt 2.0
I'm trying to get an example working from MKay book, using
starting-with.
The idea is to nest a flat structure properly, based on heading level.
The p elements are not being processed as I'd want
(duplicated etc) and the nesting isn't correct.
Any suggestions what's wrong please?
JJ
xml
<grpStart>
<h1>Usual html example, flat, with properly stacked
levels</h1> <p>Each block must have one child</p>
<h1>The instance must start with <b>h1</b></h1> <p>I.e. the
headings can follow with no more than one difference</p>
<p>1 2 3 3 4 5 4 3 etc</p>
<h2>Invalid sequences</h2>
<h2>Which might be, in fact</h2>
<p>are 1 followed by 3</p>
<p>or 4 2</p>
<h3>That's the way it goes</h3>
<p>Each block must have at least one child</p> <h3>The hard
part is persuading authors to follow style guidelines</h3>
<p>All blocks must have children</p> </grpStart>
xsl
xmlns:xs="http://www.w3.org/2001/XMLSchema-datatypes";
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<op>
<xsl:apply-templates select="//grpStart"/>
</op>
</xsl:template>
<xsl:template match="grpStart">
<xsl:for-each-group select="*"
group-starting-with="h1">
<xsl:apply-templates select="."/>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="*[starts-with(name(),'h')]">
<xsl:message>
Match on <xsl:value-of select="name()"/>
Population is <xsl:value-of select="count(current-group())"/>
</xsl:message>
<section level="{substring-after(name(),'h')}">
<head><xsl:apply-templates/></head>
<xsl:for-each-group select="current-group() except ."
group-starting-with="*[name() =
translate(name(current()),'1234','2345')]">
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
</section>
</xsl:template>
<xsl:template match="p">
<para><xsl:apply-templates/></para>
</xsl:template>
<xsl:template match="b">
<emph><xsl:apply-templates/></emph>
</xsl:template>
</xsl:stylesheet>
actual output
<op>
<section level="1">
<head>Usual html example, flat, with properly stacked
levels</head>
<para>Each block must have one child</para>
</section>
<section level="1">
<head>The instance must start with <emph>h1</emph>
</head>
<para>I.e. the headings can follow with no more than
one difference</para>
<para>1 2 3 3 4 5 4 3 etc</para>
<section level="2">
<head>Invalid sequences</head>
<para>1 2 3 3 4 5 4 3 etc</para>
<section level="2">
<head>Which might be, in fact</head>
<para>1 2 3 3 4 5 4 3 etc</para>
</section>
</section>
<section level="2">
<head>Which might be, in fact</head>
<para>1 2 3 3 4 5 4 3 etc</para>
<section level="2">
<head>Invalid sequences</head>
<para>1 2 3 3 4 5 4 3 etc</para>
</section>
</section>
<para>are 1 followed by 3</para>
<para>or 4 2</para>
<section level="3">
<head>That's the way it goes</head>
<para>or 4 2</para>
</section>
<para>Each block must have at least one child</para>
<section level="3">
<head>The hard part is persuading authors to follow
style guidelines</head>
<para>Each block must have at least one child</para>
</section>
<para>All blocks must have children</para>
</section>
</op>
___________________________________________________________
New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at
the Yahoo! Mail Championships. Plus: play games and win prizes.
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--