[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Preserving inline elements when using string functions
Subject: RE: [xsl] Preserving inline elements when using string functions From: Brook Ellingwood <brook@xxxxxxxxxxx> Date: Mon, 25 Aug 2003 09:33:18 -0700 |
Hi Marcus, > in XML one doesn't think of "inline elements in strings" but of > "a string followed by an element followed by another string". By saying "inline element" I was intending to illustrate more of what I am trying to achieve in my output than how I'm thinking of my data structure. I didn't write a DTD, but if I did, it would show a mixed content element something like this: <!ELEMENT bodytext (#PCDATA , link*)> <!ELEMENT link (#PCDATA)> <!ATTLIST link url CDATA #REQUIRED> I'm trying to see what you're getting at. I'm thinking of it as "process the child element this way, then process the parent element another way," but I think you are suggesting that I think more like "process the parent element content before the child element, then process the child element, then process parent element content after the child element." Is that right? > You didn't show us how you pass the output of the link template > to the paragraphs template. Are you using two templates in a pipeline? > Or are you using node-set functions? > > Show us, how you contruct the string and pass it to the paragraphs > template then someone will tell what's wrong with the code. > My first guess is you are using a xsl:for-each loop with xsl:value-of > to eleminate the "inline" elements. Sorry, I should have had that code in my initial mail. I've tried a few different ways to set the node context, but what's below is what I'm using now. I'm not sure of the terminology, but I guess I'm using the two templates in a pipeline. (Note that the 'string' paramater name is not an accurate description of what I'm actually trying to store in that parameter in this use of the template.) <xsl:template name="textProcess"> <xsl:for-each select="."> <xsl:call-template name="paragraphs"> <xsl:with-param name="divClass" select="'para'" /> <xsl:with-param name="string" > <xsl:call-template name="embeddedLinks" /> </xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:template> Thanks, -- Brook >> - ---------- >> Von: Brook Ellingwood >> Gesendet: Samstag, 23. August 2003 02:35 >> An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx >> Betreff: [xsl] Preserving inline elements when using string functions >> >> 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 -> |
---|---|---|
[xsl] Preserving inline elements wh, Brook Ellingwood | Thread | [xsl] why is "(chapter//footnote)[1, Robert P. J. Day |
Re: [xsl] jaxp vs xalan, Mark R. Diggory | Date | Re: [xsl] jaxp vs xalan, Joseph Kesselman |
Month |
Keywords