Subject: [xsl] element nodes in a string? From: Chris Nolte <cgn7094@xxxxxxxxx> Date: Thu, 24 May 2001 13:42:00 -0700 (PDT) |
I am a complete XML/XSLT newbie. I have spent a lot of time reading the FAQ and archives, but I can't find an answer to my problem. I have a well-formed XML document as follows: <top> <text>Each text field contains arbitrary text. It could also contain paragraph breaks, _underscores_, and ~phrases delimited by tildes~. </text> <text>Underscores and tildes are guaranteed to come in pairs, or _not at all_ in a given text field. </text> </top> What I want to do is to process each of these text fields, underlining text between underscores, italicizing text between tildes, and keeping paragraph breaks as they are, and output them in html and (later) rtf. In addition I have a few other special characters which are being replaced, such as two hyphens converted to an em dash, tab characters converted to HTML etc. My approach is to chain together a bunch of calls to a standard replace-substring template: <!-- convert two hyphens into an em dash --> <xsl:variable name='temp2'> <xsl:call-template name='replace-substring'> <xsl:with-param name='text' select='$temp1'/> <xsl:with-param name='from' select='$dash'/> <xsl:with-param name='to'>—</xsl:with-param> </xsl:call-template> </xsl:variable> <!-- convert tab characters into two 's --> <xsl:variable name='temp3'> <xsl:call-template name='replace-substring'> <xsl:with-param name='text' select='$temp2'/> <xsl:with-param name='from' select='$tab'/> <xsl:with-param name='to'>  </xsl:with-param> </xsl:call-template> </xsl:variable> I then call a template which converts _underscored text_ into <U>underscored text</U>. This works just fine. I also have a similar template which converts ~text within tildes~ to <I>text within tildes</I>. The problem is that I can't do both of them. When I pass the output of the underline template into the italicize template, the <U> and </U> are stripped out and I am left with just the <I>...</I> tags. I think this is because my italicize template calls substring-before and substring-after, and these string functions convert their arguments to strings, which effectively strips out whatever markup I have in place. How do I do what I want? Here is my underline template; the italicize is similar. <xsl:template name='underline'> <xsl:param name='text'/> <xsl:param name='und-delim'/> <xsl:choose> <xsl:when test='contains($text, $und-delim)'> <xsl:variable name='pre'> <xsl:copy-of select='substring-before($text, $und-delim)'/> </xsl:variable> <xsl:variable name='tempstr'> <xsl:copy-of select='substring-after($text, $und-delim)'/> </xsl:variable> <xsl:variable name='underlined'> <xsl:copy-of select='substring-before($tempstr, $und-delim)'/> </xsl:variable> <xsl:variable name='next'> <xsl:call-template name='underline'> <xsl:with-param name='text' select='substring-after($tempstr, $und-delim)'/> <xsl:with-param name='und-delim' select='$und-delim'/> </xsl:call-template> </xsl:variable> <xsl:copy-of select='$pre'/> <U> <xsl:copy-of select='$underlined'/> </U> <xsl:copy-of select='$next'/> </xsl:when> <xsl:otherwise> <xsl:copy-of select='$text'/> </xsl:otherwise> </xsl:choose> </xsl:template> Thanks for any help, Chris __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] <xsl:copy> does not work , Gus Tenrreiro | Thread | Re: [xsl] element nodes in a string, Wendell Piez |
Re: [xsl] Java-based XPath tool, Peter Flynn | Date | [xsl] XLST including image in HTML , Matt Gushee |
Month |