Discussion:
XSL: Transform links and sources to an absolute URL
Plew
2009-03-04 12:35:27 UTC
Permalink
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="Loading Image..." 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 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? How can I
dynamically add this to an src or href?

I`m using Saxon with XSLT 2.0.


greetings Stefan


--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
G. Ken Holman
2009-03-04 12:49:34 UTC
Permalink
Post by Plew
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?
Post by Plew
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 ) )
Post by Plew
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:

Video overview:

G. Ken Holman mailto:***@CraneSoftwrights.com
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


--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
David Carlisle
2009-03-04 12:58:39 UTC
Permalink
In addition to Ken's advice note that

<a href="www.foo.de">

is a relative URL to a file www.foo.de in the current directory, it's
probably a user error in the source, and should be http://www.foo.de
the functions that Ken mentioned won't fix that error, it's probably
best just to fix the source, but if you want the stylesheet to
dynamically fix it then you'll need some heuristics with replace()
perhaps replace(@uri,'^www\.','http://www.') or ....


David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--

Loading...