The function resolve-uri() resolves a relative URI provided as the first argument on the basis of URI provided as the second argument. If the relative URI is an empty sequence an empty sequence is returned, if the base URI is empty, a fatal error occurs.
This function does not attempt to find out whether the URI exists, it is merely a syntactic operation on two character strings.
Please note the difference between baseA and baseB. If we imagine that the base URI addresses a filesystem, the CCC in baseA is a directory, in baseB a file.
|
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="/aaa"> <xxx> <i> <xsl:value-of select="resolve-uri(bbb,baseA)"/> </i> <ii> <xsl:value-of select="resolve-uri(bbb,baseB)"/> </ii> </xxx> <yyy> <i> <xsl:value-of select="resolve-uri(ccc,baseA)"/> </i> <ii> <xsl:value-of select="resolve-uri(ccc,baseB)"/> </ii> </yyy> <zzz> <i> <xsl:value-of select="resolve-uri(ddd,baseA)"/> </i> <ii> <xsl:value-of select="resolve-uri(ddd,baseB)"/> </ii> </zzz> <ppp> <i> <xsl:value-of select="resolve-uri(eee,baseA)"/> </i> <ii> <xsl:value-of select="resolve-uri(eee,baseB)"/> </ii> </ppp> <qqq> <i> <xsl:value-of select="resolve-uri(fff,baseA)"/> </i> <ii> <xsl:value-of select="resolve-uri(fff,baseB)"/> </ii> </qqq> <rrr> <i> <xsl:value-of select="resolve-uri(ggg,baseA)"/> </i> <ii> <xsl:value-of select="resolve-uri(ggg,baseB)"/> </ii> </rrr> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa> <baseA>http://zvon.org/AAA/BBB/CCC/</baseA> <baseB>http://zvon.org/AAA/BBB/CCC</baseB> <bbb>bbb.xml</bbb> <ccc>../../CCC/ccc.xml</ccc> <ddd>../..</ddd> <eee>/eee.xml</eee> <fff>../../../../../../../</fff> </aaa> |
Output
<xxx> <i>http://zvon.org/AAA/BBB/CCC/bbb.xml</i> <ii>http://zvon.org/AAA/BBB/bbb.xml</ii> </xxx> <yyy> <i>http://zvon.org/AAA/CCC/ccc.xml</i> <ii>http://zvon.org/CCC/ccc.xml</ii> </yyy> <zzz> <i>http://zvon.org/AAA/</i> <ii>http://zvon.org/</ii> </zzz> <ppp> <i>http://zvon.org/eee.xml</i> <ii>http://zvon.org/eee.xml</ii> </ppp> <qqq> <i>http://zvon.org/../../../../</i> <ii>http://zvon.org/../../../../../</ii> </qqq> <rrr> <i/> <ii/> </rrr> |
| Previous chapter: | Arithmetics |
| Next chapter: | Transforming strings with regular expressions |
| Previous page: | Joining strings with string-join |
| Next page: | Escaping of URI with encode-for-uri, iri-to-uri, and escape-html-uri |