If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Wednesday, June 13, 2012

XSLT not powerful, really??

<?xml version="1.0"?>
    <variable name="subnode"/>
      <binding name="subnode">
      <binding name="subnode">

We want to extract all identifiers for each URI on a newline saved as text. So expected output for this sample is

There are multiple ways to solve this but the solution below is a pretty easy one. It string-joins the last part of the tokenized uri with a newline character.
<?xml version="1.0" encoding="UTF-8" ?>
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

  <xsl:output  method="text" encoding="UTF-8" media-type="text/plain"/>
  <xsl:template match="/">
    <xsl:variable name="uris" select="/sparql/results/result/binding/uri"/>
    <xsl:value-of select="string-join(for $uri in $uris return tokenize($uri, '/')[last()], '&#xa;')"/>

No comments:

Post a Comment