how to create link??

Here should go questions about transforming XML with XSLT and FOP.
guastoboy
Posts: 3
Joined: Mon Feb 20, 2006 6:37 pm

how to create link??

Post by guastoboy » Sat Apr 08, 2006 7:32 pm

hello everyone

that's my problem... i know this could be really easy for some of you.. i don't know how to create link using XSL

that's the code in XML

Code: Select all

<back>
<link type="left">pre.xml</link>
<link type="center">home.html</link>
<link type="right">ne.xml</link>
</back>

and this is the output in HTML in wanna have after XSL transformation

Code: Select all

<a href="pre.xml"><img src="aa.jpg"></a>
<a href="home.html"><img src="ab.jpg"></a>
<a href="ne.xml"><img src="ac.jpg"></a>
can someone help me? thank u so much!

Radu
Posts: 6987
Joined: Fri Jul 09, 2004 5:18 pm

Post by Radu » Mon Apr 10, 2006 8:48 am

Hi,

Here are two ways in which you can do this:

1) Use "xsl:element"

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="back">
<xsl:for-each select="link">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="text()"/>
</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="@type"/>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
2)Use XPath expressions directly in attribute values.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="back">
<xsl:for-each select="link">
<a href="{text()}">
<img src="{@type}"/>
</a>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
As you can see the transformer will evaluate what is inside curly brackets in attribute values as XPath expressions.
Here is a good XSLT tutorial: http://www.zvon.org/xxl/XSLTutorial/Boo ... tents.html

Hope this helps,
Regards, Radu.

Post Reply