user3703793
user3703793

Reputation: 11

XSLT print the first letter only

Would it be possible to print the first letter between two xml tags. For example if you have an xml code like this:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Edited by XMLSpy -->
<catalog>
<cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
</cd>

and xslt code like this:

    <?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>
     <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <tr>
        <td><xsl:value-of select="catalog/cd/title"/></td>
        <td><xsl:value-of select="catalog/cd/artist"/></td>
      </tr>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

could you get the out put in the table to be:

    My CD Collection
Title                      Artist
E                             B

instead of:

My CD Collection
    Title                      Artist
    Empire Burlesque           Bob Dylan

Upvotes: 1

Views: 1963

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

Learn the XPath string functions like http://www.w3.org/TR/xpath/#function-substring and use substring(title, 1, 1).

Upvotes: 4

Related Questions