Subject: Re: [xsl] grouping based on string but with child nodes From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 13 Oct 2008 12:47:14 -0400 |
Just to make sure I'm understanding it, a couple questions interspersed below with my understanding of what it does.
On Mon, Oct 13, 2008 at 16:40, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote: > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:dummy="urn:x-Dummy" > exclude-result-prefixes="dummy" > version="2.0">
Sticking stuff into a dummy namespace, but really I could use the namespace of the intended output couldn't I?
> <xsl:template match="title"> > <xsl:variable name="separated-titles" as="node()*"> > <xsl:apply-templates mode="separate-titles"/> > </xsl:variable>
Make a variable called separated-titles which uses a mode to apply the appropriate templates below. Does one need to cast it as node()*? I almost never do this, I guess I'm a bit sloppy with typing of things
> <xsl:variable name="titles" as="element(title)*"> > <xsl:for-each-group select="$separated-titles" > group-starting-with="dummy:dummy"> > <title> > <xsl:copy-of select="current-group()[not(self::dummy:dummy)]"/> > </title> > </xsl:for-each-group> > </xsl:variable> > <xsl:copy-of select="$titles"/> > </xsl:template>
Make a variable that does a for-each-group, here cast as element(title)* which I'm not sure I understand but I'm guessing means that the output of the variable is required to be zero-or-more title elements?
grouping with groups starting with the dummy:dummy element maybe before. And the content is to copy the entire thing but exclude from that copy the very dummy:dummy that you're grouping by. nifty!
> <xsl:template match="*" mode="separate-titles"> > <xsl:copy-of select="."/> > </xsl:template>
Copy everything in separate-titles mode.
> <xsl:template match="text()" mode="separate-titles"> > <xsl:analyze-string select="." regex="\|\|"> > <xsl:matching-substring> > <dummy:dummy/> > </xsl:matching-substring> > <xsl:non-matching-substring> > <xsl:value-of select="."/> > </xsl:non-matching-substring> > </xsl:analyze-string> > </xsl:template>
For every text node inside a title (since this is mode="separate-titles") use analyze-string to find every escaped ||, which is fine because we're just handling the text nodes.
Cool. I actually think I understand that at the moment. Must remember to use analyze-string on text nodes more....
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] grouping based on string , James Cummings | Thread | RE: [xsl] grouping based on string , Michael Kay |
[xsl] XSL XML Vertical Table Layout, Mary Pat Rhodes | Date | Re: [xsl] XSL XML Vertical Table La, G. Ken Holman |
Month |