[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] Preserving inline elements when using string functions
Subject: [xsl] Preserving inline elements when using string functions From: Brook Ellingwood <brook@xxxxxxxxxxx> Date: Fri, 22 Aug 2003 17:35:51 -0700 |
Hi, I'm trying to figure out how to preserve inline elements in a string when it gets passed through a template using string functions to manipulate the content. This is my XML: <bodytext>This is the <link url="#">link</link> This is another line of text</bodytext> My first template formats the "link" element into an HTML "a" element, using the "url" attribute as the HTML "href" attribute. I've broken the lines out for ease of reading in e-mail): <xsl:template name="embeddedLinks"> <xsl:apply-templates select="./node()"/> </xsl:template> <xsl:template match="link"> <a style="text-decoration:underline"> <xsl:attribute name="href"> <xsl:value-of select="@url"/> </xsl:attribute> foo <xsl:value-of select="."/> bar </a> </xsl:template> The output of that template is then passed to another template that finds all the CR/LF codes in the string and puts "DIV" tags around each line. <xsl:template name="paragraphs"> <xsl:param name="string" /> <xsl:param name="linebreak" select="'
'" /> <xsl:param name="divClass" /> <xsl:choose> <xsl:when test="contains($string, $linebreak)"> <DIV><xsl:attribute name="class"><xsl:value-of select="$divClass" /></xsl:attribute> <xsl:value-of select="substring-before($string, $linebreak)" /> </DIV> <xsl:call-template name="paragraphs"> <xsl:with-param name="string" select="substring-after($string, $linebreak)" /> <xsl:with-param name="linebreak" select="$linebreak" /> <xsl:with-param name="divClass" select="$divClass" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <DIV><xsl:attribute name="class"><xsl:value-of select="$divClass" /></xsl:attribute> <xsl:value-of select="$string" /> </DIV> </xsl:otherwise> </xsl:choose> </xsl:template> Individually, they work great, but in combination this is what I get for my output: <DIV class="">This is the foolinkbar</DIV> <DIV class=""> This is another line of text</DIV> Note that my test "foo" and "bar" text strings are inserted into the source text so I know the "embeddeLinks" template is working, but the "a" element and its attributes are completely missing. They must be getting lost in the pass through the "paragraphs" template as it ignores everything that isn't a string. I thought about just reversing the order in which the content goes through the templates, but then I'd lose my source "link" element the same way I'm losing my output "a" element. I've considered trying to use "copy-of" in the "paragraphs" template, but I can't quite see how to do it and still find the CR/LF codes. I'd appreciate any input that could help me figure this one out. Thanks, -- Brook XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: AW: AW: [xsl] exclude result pr, Mark R. Diggory | Thread | RE: [xsl] Preserving inline element, Brook Ellingwood |
RE: [xsl] One xsl and 2 XML's, Michael Kay | Date | Re: AW: [xsl] exclude result prefix, Mark R. Diggory |
Month |