xsl-list
[Top] [All Lists]

RE: [xsl] Targeting nodes between <lb/> elements

2008-04-27 21:12:34
This problem isn't at all easy in the general case.

From the sample submitted, however, it looks as if it can be solved in your
case by the following approach:

(a) get rid of the <p> and <sp> start and end tags, which contribute nothing
to the output

(b) the <lb/> elements are now all on the same level, so you can use
xsl:for-each-group group-starting-with="lb"

Step (a) is essentially

<xsl:variable name="temp">
  <xsl:apply-templates select="/" mode="step-a"/>
</xsl:variable>

<xsl:template match="*" mode="step-a">
 <xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>

<xsl:template match="p|sp" mode="step-a">
  <xsl:apply-templates/>
</xsl:template>

Step (b) is

<xsl:for-each-group select="$temp/*" group-starting-with="lb">
  <fo:block><xsl:apply-templates select="current-group"
mode="step-b"/></fo:block>
</xsl:for-each-group>

<xsl:template match="pb" mode="step-b"/>

<xsl:template match="speaker" mode="step-b">
  <fo:inline><xsl:value-of select="."/></fo:inline>
</xsl:template>

Now it might be that I have made incorrect inferences from your small sample
dataset. If so, you will have to try and explain the problem in more detail.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: xsl-list(_at_)diegesis(_dot_)net 
[mailto:xsl-list(_at_)diegesis(_dot_)net] 
Sent: 28 April 2008 04:45
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Targeting nodes between <lb/> elements

Hello all,

I've been lurking for a while, and would like first to 
express my thanks to all of the experts here who are so 
incredibly generous with their expertise.

I've been banging my head (painfully) against what seems to 
me should be a relatively simple issue. I've tried to find 
the solution in the obvious books and in the archives of this 
list, but at this point am completely demoralised by repeated 
failure. I'd be extremely grateful for any help in getting 
past this hurdle.

I'm trying to wrap in an <fo:block> the nodes between pairs 
of <lb/> elements. These nodes are not all siblings:

[source]
<lb/><sp><speaker>speaker1</speaker><p>text1
<lb/>text2</p></sp>
<lb/><sp><speaker>speaker2</speaker><p>text3
<lb/>text4</p></sp>

[desired output]
<fo:block><fo:inline>speaker1</fo:inline>text1</fo:block>
<fo:block>text2</fo:block>
<fo:block><fo:inline>speaker2</fo:inline>text3</fo:block>
<fo:block>text4</fo:block>

Also, I need to be able to further process some elements in 
each matched sequence (such as the <speaker> shown in the 
example). None of these elements will contain <lb/>.

Using XSLT 2.0 and Saxon 9B (and XEP), I've tried countless 
approaches involving for-each-group or simple XPath 
predicates ( << and >> ). Problems have ranged from matching 
problems to looping problems (Saxon error: "Too many nested 
apply-templates calls. The stylesheet may be looping.").

Many thanks in advance for any help you can send my way. At 
this point I'm fully prepared to be mortified by the 
inevitable simplicity of the solution...

Kitto

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>