Reputation: 69
I have a problem to add space between the firstName
and lastName
fields. I'm trying to display the first name and last name on one line, but there is no space between them. How can I add a space? These fields are from my database on SQL Server. Thank you.
<?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="/">
<html>
<head>
<style type="text/css">
.tutor
{
color: #000000;
font-family: "Arial";
font-size: large;
}
.data
{
font-family: "Arial";
font-size: large;
}
.heading
{
font-family: "Arial";
font-size: xx-large;
font-weight: bold;
color: #ABCDEF;
}
<title>Tutor Contact List</title>
</style>
</head>
<body>
<div class="heading">Tutor Contact List</div><br/>
<xsl:for-each select="list/tutorcontact">
<div class="tutor">Tutor Name:
<xsl:value-of select="lastname"/>
<xsl:value-of select="firstname"/></div>
<div class="data"><b>Phone:</b>
<xsl:value-of select="phone"/></div>
<div class="data"><b>E-Mail:</b>
<xsl:value-of select="email"/></div><br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0
Views: 2249
Reputation: 122364
<div class="tutor">Tutor Name:
<xsl:value-of select="lastname"/>
<xsl:value-of select="firstname"/></div>
In an XSLT stylesheet text nodes that consist only of whitespace are ignored by default except
<xsl:text>
orxml:space="preserve"
So the newline and spaces between Tutor Name:
and the lastname
will be preserved (because while that text node contains whitespace, it doesn't contain only whitespace) but the ones between the two value-of
elements will be ignored. If you want to have white space in the output at a place where it would be ignored in the stylesheet then you need to make it explicit with
<div class="tutor">Tutor Name:
<xsl:value-of select="lastname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="firstname"/></div>
but personally I'd just use the approach suggested by OJay and just use one value-of
with concat(lastname, ' ', firstname)
.
Upvotes: 1
Reputation: 4921
Try the XPATH concat function
<?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="/">
<html>
<head>
<style type="text/css">
.tutor
{
color: #000000;
font-family: "Arial";
font-size: large;
}
.data
{
font-family: "Arial";
font-size: large;
}
.heading
{
font-family: "Arial";
font-size: xx-large;
font-weight: bold;
color: #ABCDEF;
}
<title>Tutor Contact List</title>
</style>
</head>
<body>
<div class="heading">Tutor Contact List</div><br/>
<xsl:for-each select="list/tutorcontact">
<div class="tutor">Tutor Name:
<xsl:value-of select="concat(firstname,' ',lastname)"/>
</div>
<div class="data"><b>Phone:</b>
<xsl:value-of select="phone"/></div>
<div class="data"><b>E-Mail:</b>
<xsl:value-of select="email"/></div><br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2
Reputation: 2073
How about:
<div class="tutor">Tutor Name:
<xsl:value-of select="lastname"/>
<xsl:value-of select="firstname"/></div>
Upvotes: 0