Welcome to WebmasterWorld Guest from 54.163.25.166

Forum Moderators: httpwebwitch

Message Too Old, No Replies

xml/xsl: change url for unknown ip-addres within xsl

xml xsl change content

     
8:31 am on Aug 31, 2009 (gmt 0)

New User

5+ Year Member

joined:Aug 31, 2009
posts: 1
votes: 0


Hi,

I have the following issue:
a database gives a certain xml document which is styled and then showed using a xsl file. we can only change the xsl file, so adjustments have to be made here. the xml file contains a value named <ext_doc> which contains an url. we want to check if the ip of the requesting computer is from or internal network (192.168.x.x) or from someone external. when the requester is coming from our internal network, the url just has to be shown, but when it's an other visitor; the url has to be changed to [ourProxy.com...]

how can I make this such that the xsl file can read the visitors ip-address and when needed change the url?

thanks in advance for your help

the template for the url in the xsl file now looks like this:

<xsl:template match="ext_doc">
<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="." />
</xsl:attribute>
Full text
</a>
<xsl:if test="position()!=last()"> </xsl:if>
</xsl:template>
1:17 pm on Sept 17, 2009 (gmt 0)

Moderator This Forum from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


Welcome to WebmasterWorld, maartenN!

XSLT won't be able to do this on its own. you'll need a platform that can perform more complex tasks.

for instance, in PHP there is gethostbyname [ca.php.net]($ip) which will tell you the IP associated with a URL's host name, and $_SERVER['REMOTE_ADDR'] which tells you the user's IP.

If all you can do is edit an XSLT file, then your hands are tied... perhaps you should be sending all your outbound links through the proxy, and let the proxy script decide which ones to proxify, and which ones to redirect directly to the passed-in URL.

1:28 pm on Sept 17, 2009 (gmt 0)

Moderator This Forum from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


if the XML included the user's IP address, then you could do it with an <xsl:if> condition