XML/XSLT stylesheet/RDF

Материал из Web эксперт
Перейти к: навигация, поиск

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.ru/rdf/simple/0.9/">
  <channel>
    <title>User"s Domain</title>
    <link>http://www.wbex.ru</link>
    <description>XML and DHTML Tutorials</description>
  </channel>
  <image>
    <title>Learning Center</title>
    <url>http://www.wbex.ru/jbutton.jpg</url>
    <link>http://www.wbex.ru</link>
  </image>
  <item>
    <title>An Introduction to XML</title>
    <link>http://www.wbex.ru</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.ru/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.wbex.ru">An Introduction to XML</a><br>