BASICS

ADMINISTRATION

DEVELOPMENT

SUPER ADMIN

  LAST UPDATED
5/24/2013

Transforming External Data Sources Into XSL

XSL allows developers to fetch external documents to be parsed and processed to create new transformed content. There are two XSLT functions that allow developers to achieve this goal — xsl:doc and xsl:unparsed-text.

xsl:doc

The xsl:doc function finds an external XML document by resolving a URI reference, parses the XML into a tree structure, and returns its root node. The URI used as input to the doc() function should identify an XML document. If the URI is invalid, the resource is unavailable, or the resource is not an XML document, then OU Campus reports the error.

Function Declaration

doc(href)

Example

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet SYSTEM "http://commons.omniupdate.com/dtd/
standard.dtd">
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/
XSL/Transform" xmlns:ou="http://omniupdate.com/XSL/Variables">
<xsl:template match="/">
     <xsl:copy-of select=
"doc('http://example.com/sample.xml')"/>
</xsl:template>

</xsl:stylesheet>

Attributehref (mandatory): The URI used to locate the document to be loaded.

Example xsl:doc Call

Example

<!--?xml version="1.0" encoding="iso-8859-1"?-->
<!DOCTYPE xsl:stylesheet SYSTEM "http://commons.omniupdate.com/dtd/standard.dtd" >
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:media="http://search.yahoo.com/mrss/">
<xsl:template match="/">
<html>
    <head>
          <title>News Listing</title>
    </head>
    <body>
          <xsl:for-each select="doc('http://www.gallenauniversity.com/_resources/rss/news.xml')/rss/channel/item">
           <ul>
             <li><a href="{./link/node()}">
<xsl:copy-of select="./title/node()"/></a></li>
             <li><xsl:copy-of select="./description/node()"/></li>              <li><img src="{./media:content/media:thumbnail/@url}" alt=""/></li>
     <li><xsl:copy-of select="./media:content/media:title/node()"/></li>  
            </ul>
            </xsl:for-each>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

xsl:unparsed-text

The xsl:unparsed-text function returns the content of an external file in string format by resolving the provided URI. This function is quite similar to the xsl:doc except that unparsed-text returns text rather than XML.

Function Declaration

unparsed-text(href)

Example

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet SYSTEM "http://commons.omniupdate.com/dtd/
standard.dtd">
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/
XSL/Transform" xmlns:ou="http://omniupdate.com/XSL/Variables">
<xsl:template match="/">
     <xsl:copy-of select=
"unparsed-text('http://example.com/sample.csv')"/>
</xsl:template>

</xsl:stylesheet>

Attributehref (mandatory): The URI used to locate the document to be loaded.

 


Was this page helpful?

Additional Comments:


(Include your email address if you would like a reply)