|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Dealing with breaking out mixed content
Hi, all!
I'm back with another question -- I hope it doesn't fall into the category of "qualitative decline." I am still learning, but I'm trying to do my homework before asking questions. I don't seem to be able to come up with a good answer for this one though. 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? Thanks again for all your previous assistance, and thank you in advance for helping me with this one. 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> XSLT FRAGMENT: <xsl:template name="separate-lists-char1"> <xsl:param name="list" /> <xsl:variable name="nlist" select="concat(normalize-space($list),'&(!!char1!!);')" /> <xsl:variable name="first" select="substring-before($nlist,'&(!!char1!!);')" /> <xsl:variable name="rest" select="substring-after($nlist,'&(!!char1!!);')" /> <xsl:text>
</xsl:text> <p class="{@class}"> <span><xsl:text>&(!!char1!!); </xsl:text></span> <xsl:apply-templates select="$first" /> </p> <xsl:if test="$rest"> <xsl:call-template name="separate-lists-char1"> <xsl:with-param name="list" select="$rest" /> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template match="oeb:p[oeb:span[starts-with(.,'&(!!char1!!);') and position() != 1]]"> <xsl:call-template name="separate-lists-char1"> <xsl:with-param name="list" select="." /> </xsl:call-template> </xsl:template> --Chris ---------------------------------------------------------------------------------------- Texterity ~ XML and PDF ePublishing Services ---------------------------------------------------------------------------------------- Chris Loschen, XML Developer Texterity, Inc. 144 Turnpike Road Southborough, MA 01772 USA tel: +1.508.804.3033 fax: +1.508.804.3110 email: loschen@xxxxxxxxxxxxx http://www.texterity.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








