|
Subject: Re: [xsl] Move elements to preceding parent From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 17 Jun 2009 13:37:13 -0700 |
I really appreciate your code and comments, but after reading it many times, I can't reach to the bottom of the logic here. I'm a newbie so forgive my stupid questions.
1. Why do we need the outer most copy element: > <xsl:template match="body"> > <xsl:copy>
How does it work in combination with xsl:for-each-group?
2. Can you please explain the group-ending-with selection?
Why do we need *[not(self::p)] ? Doesn't it mean all except p elements?
<xsl:template match="body">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each-group select="*"
group-ending-with="*[not(self::p)] |
p[span/@class='chapter'] |
p[matches(span[last()],
'[.?"]$')]">
<!--now the information is grouped by p elements that end as
required-->
<xsl:choose>
<xsl:when test="current-group()[last()]
[self::p][matches(span[last()],'[.?"]$')]">
<!--in a group of p elements that end as required-->
<xsl:copy>
<xsl:copy-of select="@*"/>
<!--preserve the content of the first of these p elements-->
<xsl:apply-templates/>
<!--preserve only the span elements and indentation from the
rest;
(the indentation is needed because this is paragraph
white-space)-->
<xsl:apply-templates select="current-group()[position()>1]/
(text()[not(normalize-space())] |
span)"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<!--in another kind of group so just copy these using identity-->
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
-- Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx 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] Move elements to precedin, Israel Viente | Thread | Re: [xsl] Move elements to precedin, Israel Viente |
| Re: [xsl] Move elements to precedin, Israel Viente | Date | RE: [xsl] Entity escaping/translati, Michael Kay |
| Month |