Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML / XSL Substring

XML / XSL Substring

Scheduled Pinned Locked Moved XML / XSL
xmlphphtmldatabasewpf
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brian_Mitchell
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • B Brian_Mitchell

      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

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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>

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups