[opensource-dev] [IDEA] built-in chatlog wikification (was: Esbee Linden's OH Transcript Posted for 09/01/2010)

Joshua Bell josh at lindenlab.com
Thu Sep 2 12:34:47 PDT 2010


On Thu, Sep 2, 2010 at 10:49 AM, Ricky <kf6kjg at gmail.com> wrote:

> Could even be
> potentially possible with LLSD since it is based in xml, but may be
> more difficult to make a good XSL document due to the fact that LLSD
> is not context-free. (The descriptor and content are sibling nodes.
> This caused me much headache many months ago!)
>

You can use XPaths like key[text()='KEYNAMEHERE']/following-sibling::* to do
key/value processing over XML-serialized LLSD in XSLT.

For example, given this XML-serialized LLSD:

<?xml version="1.0" encoding="utf-8"?>
<llsd>
  <array>
    <map>
      <key>speaker</key>
      <string>Joshua Linden</string>
      <key>text</key>
      <string>Hello, world</string>
      <key>timestamp</key>
      <date>2010-09-02T12:11:44Z</date>
    </map>
    <map>
      <key>speaker</key>
      <string>Joshua Linden</string>
      <key>text</key>
      <string>It's lonely here</string>
      <key>timestamp</key>
      <date>2010-09-02T12:12:32Z</date>
    </map>
  </array>
</llsd>

You can process it with this XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />

<xsl:template match="/llsd/array">
  <html>
    <title>Chat Log</title>
    <table>
      <xsl:for-each select="map">
        <xsl:call-template name="entry" />
      </xsl:for-each>
    </table>
  </html>
</xsl:template>

<xsl:template name="entry">
  <tr>
    <td>
       <xsl:value-of select="key[text()='timestamp']/following-sibling::*"
/>
    </td>
    <td>
       <xsl:value-of select="key[text()='speaker']/following-sibling::*" />
    </td>
    <td>
       <xsl:value-of select="key[text()='text']/following-sibling::*" />
    </td>
  </tr>
</xsl:template>

</xsl:stylesheet>

To get this HTML output:

<html>
<title>Chat Log</title>
<table>
<tr>
<td>2010-09-02T12:11:44Z</td>
<td>Joshua Linden</td>
<td>Hello, world</td>
</tr>
<tr>
<td>2010-09-02T12:12:32Z</td>
<td>Joshua Linden</td>
<td>It's lonely here</td>
</tr>
</table>
</html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.secondlife.com/pipermail/opensource-dev/attachments/20100902/b5cf608b/attachment.htm 


More information about the opensource-dev mailing list