Jump to content
  • Advertisement
Sign in to follow this  
metrix

[web] placing a newline with XSL

This topic is 4329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I have a feeling this is really simple but I've been busting my head on it. Say somewhere in my XML document I have the following node: <message>This is a message!</message> and then my XSL document has the following template to handle it: <xsl:template match="message"> <p> <xsl:value-of select="."/> </p> </xsl:template> I simply display the value of the node in an html paragraph. Question: How do I break that message across two lines? For example, I want to display the following in my browser: This is a message! rather than This is a message! Thanks metrix

Share this post


Link to post
Share on other sites
Advertisement
as far as i know, you can't. In some way you have to tell the XSL/XML parser where that break should occur by either seperating the message into parts e.g.

<!-- XML -->
<body>
<message>
<message-part>This is</message-part>
<message-part>a test!</message-part>
</message>
</body>

<!-- XSL -->
<xsl:template match="/">
<p>
<xsl:for-each select="body/message/message-part">
<xsl:value-of select="."/><br/>
</xsl:for-each>
</p>
</xsl:template>




if you are just trying to fit the text inside a confined space
<xsl:template match="message">
<div style="width:50px">
<xsl:value-of select="."/><br/>
</p></div>
</xsl:template>

Share this post


Link to post
Share on other sites
Look up XSL whitespace handling. I'm sure you can set a property which causes it to respect whitespace. It's been a while since I've done XSLT.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!