Re: [xsl] XSL: Transform links and sources to an absolute URL

Subject: Re: [xsl] XSL: Transform links and sources to an absolute URL
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 04 Mar 2009 07:49:34 -0500
At 2009-03-04 13:35 +0100, Plew wrote:
Hello

this is my first post here, so i hope somebody can help me?
I have an XML file like this, with relative and absolute URL`s

<images>
<img src="http://www.foo.de/test/bar.jpg"; alt="" width="800" height="600" />
<img src="/test/bar.jpg" alt="" width="800" height="600" />
</images>
<links>
<a href="www.foo.de">...hi there</a>
<a href="/test/test.html">bar</a>
</links>


..and know I need a way to append the absolute URL

Which absolute URL? The ones from the image elements that are absolute, or the absolute URI of the XML file itself?


to the relative path`s to prevent errors, when i`m generating HTML on my server with an xslt.
Whats the best way? Pass a parameter with the URL to the XSLT?

Yes, if that is different than the absolute URI of the file itself.


For any given node you in the source tree can get the absolute URI of the source base document in XSLT 2 using:

document-uri( root( $node ) )

How can I dynamically add this to an src or href?

resolve-uri( $relative-uri, $base-uri )


I hope this helps.

. . . . . . . . . . . Ken

--
XQuery/XSLT training in Prague, CZ 2009-03 http://www.xmlprague.cz
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread