Jump to content

How to put a space in XSLT file


paulfrancis99

Recommended Posts

I am making a dating site using XML and in my XSLT file I have the following section of code linking to my XML file<div class="about"> <xsl:value-of select="ethnicity"/> <xsl:value-of select="gender"/> seeking <xsl:value-of select="seeking"/> </div><p/>This results in the following being displayed in the HTML browser"CaucasianFemale seeking Male"How do I put a space between Caucasian and female so when displayed in HTML it displays as "Caucasian Female seeking Male"I've tried everythingThanks

Link to comment
Share on other sites

your best bet is to use <xsl:text> </xsl:text> for a blank spaceif you use 160;  (the space character, I added a space between # and 1 so that you can see it) it can display unexpected results depending on the browser encoding

<xsl:value-of select="ethnicity"/><xsl:value-of select="gender"/><xsl:text> seeking </xsl:text><xsl:value-of select="seeking"/>

Link to comment
Share on other sites

so it appears that your source data ("ethnicity"), has this value in it: 'CaucasianFemale". Without a space. So your question really is , how do I break my source XML data into two pieces so that a space appears. My first thought is to correct the source. If not possible, what should the rules be then? Do you break at the second uppercase letter? It would be helpful to see the XML source that you are working from.

Link to comment
Share on other sites

no the source data ("ethnicity") has the value "Caucasian" in it. Then the source data ("######") has the value "Female" in it. Then when they are displayed on screen there is no space in it and this is what I need to know how to do. The source data XML aren't joined together there is only 1 word in each field. :)

Link to comment
Share on other sites

try this

<div class="about"><xsl:apply-templates select="ethnicity"/><xsl:value-of select="gender"/> seeking <xsl:value-of select="seeking"/></div><p/><xsl:template match="ethnicity">	<xsl:value-of select="."/>	<xsl:if test="position() = 1"><xsl:text> </xsl:text></xsl:if></xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...