Jump to content

Can XSLT output contain dynamic hyperlinks


damian10

Recommended Posts

Hi everyone,I hope this is something that someone can help me with as I'm not very experienced with doing this.What I'm trying to do is design a search facility for my web page that will query an XML file and format the output using XSLT. The output needs to contain hyperlinks to other pages. It would seem simple enough to add a hyperlink into the XSLT code but as the XML file will contain data that should link to different pages the hyperlink would need to change.Here is an axamplpe of an XML file that would need some sort of dynamic link<xml version="1.0?"> <vehicle> <car> <manufacturer>Ford</manufacturer> <model>Escort</model> </car> <car> <manufacturer>Ford</manufacturer> <model>Focus</mmodel> </car> <car> <manufacturer>Vauxhall</manufacturer> <model>Vectra</model> </car> </vehicle>From the above example the output could be formatted to link to a page showing info on the Ford cars as they are both from the same manufacturer but when searching for a Vauxhall model the link would show the page for the Ford models. This is just a very basic example as the real xml files will be much larger and will be added to.if there is a simple solution to this then I apologise as I stated before I'm not very experienced with this and I could not find anything in the tutorials about this.thanks for your time.

Link to comment
Share on other sites

Well, this XML is very plain. What should the output URLs looks like? If we suppose they are relative links to the ouput file which need to be like "manufacturer/model", then you can simply use AVT, like:

<xsl:for-each select="car"><a href="{manufacturer}/{model}"><xsl:value-of select="concat(manufacturer,' ',model)"/></a></xsl:for-each>

More complex situations requre either specfying the URL somewhere within the XML or assemblying it with conditions in the XSLT.

Link to comment
Share on other sites

Well, this XML is very plain. What should the output URLs looks like? If we suppose they are relative links to the ouput file which need to be like "manufacturer/model", then you can simply use AVT, like:
<xsl:for-each select="car"><a href="{manufacturer}/{model}"><xsl:value-of select="concat(manufacturer,' ',model)"/></a></xsl:for-each>

More complex situations requre either specfying the URL somewhere within the XML or assemblying it with conditions in the XSLT.

Thanks for that boen_robot, I gave it a try and it works, needs some fine tuning but I should be able to figure it out. :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...