Click here to Skip to main content
15,881,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1. How do i fetch 1 by 1 letter from word in XSLT.

EXample: i have xml like


XML
  <cricket>
  <player>
    <name>sachin Tendulkar </name>
  </player>
   <player>
    <name>Virat Kohili </name>
  </player>
</cricket>


i want to display like
XML
<tr>
  <td> s </td>
  <td> a </td>
  <td> c </td>
  <td> h </td>
  <td> i </td>
  <td> n </td>
  <td>   </td>
  <td> T </td>
  <td> e </td>
  <td> n </td>
  <td> d </td>
  <td> u </td>
  <td> l </td>
  <td> k </td>
  <td> a </td>
  <td> r </td>
</tr>

same for virat kohili name .i want to every word in <table><tbody><tr><td> tag,for jumble the word or exchange the position of word in front end ....
Plz reply soon...
thanks.
Posted
Updated 29-Nov-13 3:32am
v3

1.Get instance of your XML file
2.use xmlreader to get xml members
C#
string xml = "  <span><myVal>Sachin</myVal><myVal>Virat</myVal><myVal></span>";
XmlReader xr = XmlReader.Create(new StringReader(xml));
var xmlMembers = from members in XElement.Load(xr).Elements() select members;

foreach (XElement x in xmlMembers)
{
    // nodeValue will has Sachin in it
    var nodeValue = x.Value;
}

with this nodevalue you can manipulate furthur as per your need and Jumble the word and show it int UI
 
Share this answer
 
v2
HTML
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML">
	xmlns:qti="http://www.imsglobal.org/xsd/imsqti_v2p1">
  <xsl:output indent="yes" />
  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>
  <xsl:template match="name" name="Test">
          <xsl:param name="text" select="node()" />
          <xsl:if test="$text != ''">
            <xsl:variable name="letter" select="substring($text, 1, 1)" />           
            <td>
              <xsl:copy-of select="$letter" />
            </td>
            <xsl:call-template name="Test">
              <xsl:with-param name="text" select="substring-after($text, $letter)" />
            </xsl:call-template>
          </xsl:if>
  </xsl:template>
</xsl:stylesheet>
 
Share this answer
 
v3
Comments
Arpana Mallik 2-Dec-13 8:12am    
thanks Prasannala.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900