Subject: Re: [xsl] Dealing with breaking out mixed content From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Sat, 07 Dec 2002 16:03:26 +0100 |
I have some mixed content paragraphs which I need to break up into multiple paragraphs, each one beginning with a specified string. See my sample input and desired output below. (I'll clean up some of the other cruft like the extra br elements later.) I tried to set up some templates (which I've included below) for this based on the example in Michael Kay's XSLT 2nd ed., p. 550. However, Mr. Kay's script was dealing with a pure string of #PCDATA and I've got nodes mixed in, so I'm getting an error that I cannot "convert #STRING to a NodeList!" (If I've misunderstood any of that, please let me know.) What am I doing wrong? Or do I need to totally rethink my approach, because "substring-before" and "substring-after" are meant to work on strings, not mixed content?
If that's it, is there a way to accomplish what I need to do?
<xsl:key name="nodes" match="/p/node()" use="generate-id((../node()[1] | (preceding-sibling::span|self::span)[starts-with(., '&(!!char1!!);')])[last()])"/>
<xsl:template match="node()" mode="start-group"> <p class="extract-9"> <xsl:copy-of select="key('nodes', generate-id())"/> </p> </xsl:template>
(../node()[1] | (preceding-sibling::span | self::span) [starts-with(.,'&(!!char1!!);')]) [last()]
Thanks again for all your previous assistance, and thank you in advance for helping me with this one.<xsl-code snipped="true"/>
SAMPLE INPUT:
<p class="extract-9"><span class="extract-7"><b>Did You Know?</b></span>How to read a car ad:<span>&(!!char1!!);</span> <i>Low mileage</i> means <i>the odometer doesn’t work<br /></i><span>&(!!char1!!);</span> <i>All original</i> means <i>needs new everything<br /></i><span>&(!!char1!!);</span> <i>Health forces sale</i> means <i>I’m sick of this car<br /></i><span>&(!!char1!!);</span> <i>Must see</i> means <i>I won’t put anything in writing<br /></i><span>&(!!char1!!);</span> <i>Runs like a top</i> means <i>wobbles when driven slowly<br /></i><span>&(!!char1!!);</span> <i>Mint</i> means <i>there’s an old roll of Lifesavers under the seat<br /></i><span>&(!!char1!!);</span> <i>Rare</i> means <i>most examples of this model fell apart long ago</i></p>
DESIRED OUTPUT:
<p class="extract-9"><span class="extract-7"><b>Did You Know?</b></span>How to read a car ad:</p>
<p class="extract-9"><span>&(!!char1!!);</span> <i>Low mileage</i> means <i>the odometer doesn’t work<br /></i></p>
<p class="extract-9"><span>&(!!char1!!);</span> <i>All original</i> means <i>needs new everything<br /></i></p>
<p class="extract-9"><span>&(!!char1!!);</span> <i>Health forces sale</i> means <i>I’m sick of this car<br /></i></p>
<p class="extract-9"><span>&(!!char1!!);</span> <i>Must see</i> means <i>I won’t put anything in writing<br /></i></p>
<p class="extract-9"><span>&(!!char1!!);</span> <i>Runs like a top</i> means <i>wobbles when driven slowly<br /></i></p>
<p class="extract-9"><span>&(!!char1!!);</span> <i>Mint</i> means <i>there’s an old roll of Lifesavers under the seat<br /></i></p>
<p class="extract-9"><span>&(!!char1!!);</span> <i>Rare</i> means <i>most examples of this model fell apart long ago</i></p>
--Chris
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Dealing with breaking out mix, Chris Loschen | Thread | Re: [xsl] Dealing with breaking out, Chris Loschen |
Re: [xsl] Identity of Documents Puz, W. Eliot Kimber | Date | Re: [xsl] Identity of Documents Puz, David Rosenborg |
Month |