XML / XSL Substring
-
I am trying to format my html table as i have a field labeled description with multiple lines and i was wondering is there anyway to format them using a substring function, i would also like them with bullet points any help?
<field name="Description" index="description">
This is a test script designed to illustrate DDML features.
Read some data
View the data
Require some libraries (actually we don't, but it shows off some of the functionality)
Do some funky Emax model stuff ...
Sample code from <a href="http://www.e-booksdirectory.com/details.php?ebook=1791">An introduction to R</a>
</field>Above is a samble of what i want, for each line i want ot use a substring to read each line stick it in a bullet point and move onto the next untill they are also done. also i need to find away to carry over the link to the html table. below is sample of my stylesheet.
<table width="700" border="1" align="center" style="font-family:verdana font-size:10pt">
<tr bgcolor = "#cccccc"> <td width="130" align="center"><b>Title</b></td> <td align="center"><b>Information</b></td> </tr> <xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="field">
<tr>
<td><xsl:value-of select="@name" /></td><td><xsl:value-of select="." /></td>
</tr>
</xsl:template></xsl:stylesheet>
I would appreicate any help possible, thank you
-
I am trying to format my html table as i have a field labeled description with multiple lines and i was wondering is there anyway to format them using a substring function, i would also like them with bullet points any help?
<field name="Description" index="description">
This is a test script designed to illustrate DDML features.
Read some data
View the data
Require some libraries (actually we don't, but it shows off some of the functionality)
Do some funky Emax model stuff ...
Sample code from <a href="http://www.e-booksdirectory.com/details.php?ebook=1791">An introduction to R</a>
</field>Above is a samble of what i want, for each line i want ot use a substring to read each line stick it in a bullet point and move onto the next untill they are also done. also i need to find away to carry over the link to the html table. below is sample of my stylesheet.
<table width="700" border="1" align="center" style="font-family:verdana font-size:10pt">
<tr bgcolor = "#cccccc"> <td width="130" align="center"><b>Title</b></td> <td align="center"><b>Information</b></td> </tr> <xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="field">
<tr>
<td><xsl:value-of select="@name" /></td><td><xsl:value-of select="." /></td>
</tr>
</xsl:template></xsl:stylesheet>
I would appreicate any help possible, thank you
One thing I see a problem with immediately - the <a> tag won't be included in the text for <field> - it's a nested tag. Aside form that, this is roughly what you need:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
<xsl:apply-templates select="//field"/>
</xsl:template><!--
Template for a field element. Apply template for each of its text nodes.
-->
<xsl:template match="field">
<ul>
<xsl:apply-templates select="text()"/>
</ul>
</xsl:template><!--
Template for text() in a field element. Apply the line-splitting algorithm to the text
-->
<xsl:template match="/field/text()">
<xsl:call-template name="t">
<xsl:with-param name="s" select="."/>
</xsl:call-template>
</xsl:template><!--
Template t takes one string parameter s. It takes off the first line
then recurses, terminating when the input parameter is the empty string
-->
<xsl:template name="t">
<xsl:param name="s"/>
<!--
Is there any text to process?
-->
<xsl:if test="string-length($s)>0">
<!--
first = text before the first line break (or null if it's the last, unterminated line)
-->
<xsl:variable name="first" select="substring-before($s, ' ')"/>
xsl:choose
<!--
Output first if it has content
-->
<xsl:when test="string-length($first)>0">
<li><xsl:value-of select="$first"/></li>
</xsl:when>
xsl:otherwise
<!--
Output the input string if it doesn't contain a line break
-->
<xsl:if test="substring($s,1,1)!=' '">
<li><xsl:value-of select="$s"/></li>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<!--
Recurse, passing in the text after the first line break
-->
<xsl:call-template name="t">
<xsl:with-param name="s" select="substring-after($s, ' ')"/>
</xsl:call-template>