Transform RDF document : RDF « XSLT stylesheet « XML






Transform RDF document


File: Data.xml
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns="http://my.netscape.com/rdf/simple/0.9/">
  <channel>
    <title>User's Domain</title>
    <link>http://www.java2s.com</link>
    <description>XML and DHTML Tutorials</description>
  </channel>
  <image>
    <title>Learning Center</title>
    <url>http://www.java2s.com/jbutton.jpg</url>
    <link>http://www.java2s.com</link>
  </image>
  <item>
    <title>An Introduction to XML</title>
    <link>http://www.java2s.com</link>
  </item>


</rdf:RDF>

File: Transform.xslt
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="rdf rss"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:rss="http://my.netscape.com/rdf/simple/0.9/">
  <xsl:output method="html" indent="yes" />
  <xsl:template match="/">
    <xsl:apply-templates select="rdf:RDF/rss:item" />
  </xsl:template>

  <xsl:template match="rdf:RDF/rss:item">
    <a href="{rss:link}">
      <xsl:value-of select="rss:title" />
    </a>
    <br />
    <xsl:text>&#013;</xsl:text>
  </xsl:template>
</xsl:stylesheet>

Output:

<a href="http://www.java2s.com">An Introduction to XML</a><br>

 








Related examples in the same category