| | |
Transforming XML with XSLT
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
How do I preserve things like tabs and carriage returns in text? when transforming XML to XHTML with XSL. For example:
XML
XSL
The carriage return between the text line:
a less than <
And
a greater than >
is lost when rendered in the browser, I sort of understand why that is, but I don't know how to apply XML or XSL to include/preserve or force the carriage return.
XML
HTML and CSS Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="article.xsl"?> <content> <article name="Test Article"> <heading>Test Article</heading> <subheading>Special Chars</subheading> <paragraph> <text> a less than < a greater than > </text> <text type="code"> some code. </text> </paragraph> </article> </content>
XSL
HTML and CSS Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="content"> <xsl:apply-templates select="article" /> </xsl:template> <xsl:template match="article"> <h2><xsl:value-of select="heading" /></h2> <xsl:value-of select="subheading" /> <xsl:for-each select="paragraph"> <p> <xsl:for-each select="text"> <xsl:choose> <xsl:when test="@type = 'link'"> <a href="{@href}" target="{@target}"> <xsl:value-of select="." /> </a> </xsl:when> <xsl:when test="@type = 'code'"> <div class="code"> <xsl:value-of select="." /> </div> </xsl:when> <xsl:otherwise> <xsl:value-of select="." /> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet>
The carriage return between the text line:
a less than <
And
a greater than >
is lost when rendered in the browser, I sort of understand why that is, but I don't know how to apply XML or XSL to include/preserve or force the carriage return.
Is there a way to make substitutions? I know nothing of xslt, but you want to substitute a <br /> tag where ever the style sheet encounters the >
If you are generating the xml yourself, you might try this:
Hope this helps..
If you are generating the xml yourself, you might try this:
HTML and CSS Syntax (Toggle Plain Text)
<text> <table> <tr> <td>a less than</td> <td>a greater than</td> </tr> </table </text>
Hope this helps..
does anything in http://www.xml.com/pub/a/2001/11/07/whitespace.html help?
Thanks guys.
I followed Daves links, it tells me XSL preserves whitespace by default. What I havn't mentioned is that in my particular scenario i'm using client javascript transformNode function and I can't be certain if that is doing what it should.
Anyway I have plenty of options to try now. If I nail it, i'll post the horrid details.
I followed Daves links, it tells me XSL preserves whitespace by default. What I havn't mentioned is that in my particular scenario i'm using client javascript transformNode function and I can't be certain if that is doing what it should.
Anyway I have plenty of options to try now. If I nail it, i'll post the horrid details.
![]() |
Similar Threads
- XML to XSLT for XML with value in attribute (XML, XSLT and XPATH)
- convert xml using xslt (XML, XSLT and XPATH)
Other Threads in the HTML and CSS Forum
- Previous Thread: How to create a web page with scrolling menus to specific entries
- Next Thread: JS Ticker
Views: 6830 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for HTML and CSS
2002 appointments asp background backgroundcolor beta browser bug calendar cart center cgi code codeinjection corporateidentity create css deleted design development displayimageinsteadofflash dreamweaver drupal emailmarketing epilepsy explorer firefox flash font fonts form format free frontpage google griefers hackers hitcounter hover html ide ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft missing mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization perl pnginie6 positioning problem scroll seo shopping studio swf swf. templates textcolor theme timecolor titletags url urlseparatedwords visual visualization web webdevelopment webform website windows7 wordpress xml xsl






