C
Christoph
I'm still learning how to write stylesheets and the ones I've come up with
for learning purposes are pretty simple and straightforward. I can get it
to work, but probably not in the most ideal way.
I have a node in the XML I'm transforming that contains CRLFs. I did a
search on how to do a search/replace but am not 100% sure how to fit it into
my template. Here is a sample xml record:
<UserRecordRoot>
<UserItems>
<UserItem>
<uid>MyUserId</uid>
<lastLogin>2002-02-21 01:04:36</lastLogin>
<country>USA</country>
<comments>
Comments Line 1
Comments Line 2
Comments Line 3
</comments>
</UserItem>
</UserItems>
</UserRecordRoot>
Here is my XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl
utput method="html"/>
<xsl:template match="UserItems">
<html>
<head>
<title>Game Sets</title>
</head>
<body>
<h1>Users</h1>
<table border="1" width="100%">
<tr>
<th>User</th>
<th>Last Login</th>
<th>Country</th>
<th>Comments</th>
</tr>
<xsl:for-each select="UserItem">
<tr>
<td valign="top">
<xsl:copy-of select="name"/>
</td>
<td valign="top">
<xsl:copy-of select="lastLogin"/>
</td>
<td valign="top">
<xsl:copy-of select="country"/>
</td>
<td valign="top" width="25%">
<xsl:value-of select="comments"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="comments">
<xsl:call-template name="replace">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:template>
// I found the below on one of the sites listed in my google search
<xsl:template name="replace">
<xsl
aram name="string"/>
<xsl:choose>
<xsl:when test="contains($string,'
')">
<xsl:value-of select="substring-before($string,'
')"/>
<br/>
<xsl:call-template name="replace">
<xsl:with-param name="string"
select="substring-after($string,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl
therwise>
<xsl:value-of select="$string"/>
</xsl
therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The UserItems template is simpe, straightfoward and works. I'm just not
sure how to make it so that the comments node matches the template of the
same name and thus triggering the replace template. How can I get this
done?
thnx,
Christoph
for learning purposes are pretty simple and straightforward. I can get it
to work, but probably not in the most ideal way.
I have a node in the XML I'm transforming that contains CRLFs. I did a
search on how to do a search/replace but am not 100% sure how to fit it into
my template. Here is a sample xml record:
<UserRecordRoot>
<UserItems>
<UserItem>
<uid>MyUserId</uid>
<lastLogin>2002-02-21 01:04:36</lastLogin>
<country>USA</country>
<comments>
Comments Line 1
Comments Line 2
Comments Line 3
</comments>
</UserItem>
</UserItems>
</UserRecordRoot>
Here is my XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl
<xsl:template match="UserItems">
<html>
<head>
<title>Game Sets</title>
</head>
<body>
<h1>Users</h1>
<table border="1" width="100%">
<tr>
<th>User</th>
<th>Last Login</th>
<th>Country</th>
<th>Comments</th>
</tr>
<xsl:for-each select="UserItem">
<tr>
<td valign="top">
<xsl:copy-of select="name"/>
</td>
<td valign="top">
<xsl:copy-of select="lastLogin"/>
</td>
<td valign="top">
<xsl:copy-of select="country"/>
</td>
<td valign="top" width="25%">
<xsl:value-of select="comments"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="comments">
<xsl:call-template name="replace">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:template>
// I found the below on one of the sites listed in my google search
<xsl:template name="replace">
<xsl
<xsl:choose>
<xsl:when test="contains($string,'
')">
<xsl:value-of select="substring-before($string,'
')"/>
<br/>
<xsl:call-template name="replace">
<xsl:with-param name="string"
select="substring-after($string,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl
<xsl:value-of select="$string"/>
</xsl
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The UserItems template is simpe, straightfoward and works. I'm just not
sure how to make it so that the comments node matches the template of the
same name and thus triggering the replace template. How can I get this
done?
thnx,
Christoph