J
Jyrki Keisala
I have an XML file:
<document>
<record>
<element1>Text</element1>
<element2>More text</element2>
<element3>Even more text</element3>
<element4>Some text <link><title>Google</title><url>
http://www.google.com</url></link> with a link.</element4>
</record>
<record>
<element1>Yeah</element1>
<element2>Now the link is here: <link><title>W3C</title><url>
http://www.w3c.org</url></link></element2>
<element3>Something else</element3>
<element4>...and more text</element4>
</record>
</document>
which I want to convert to an HTML table. One possibility for the
conversion is to use for-each loop in XSL as in
(XSL1)
<xsl:template match="/">
<html>
<head>
<title>My HTML table</title>
</head>
<body>
<table border="1">
<head>
<tr>
<td><b>Element1</b></td>
<td><b>Element2</b></td>
<td><b>Element3</b></td>
<td><b>Element4</b></td>
</tr>
</head>
<xsl:for-each select="document/record">
<tr>
<td><xsl:value-of select="element1" /></td>
<td><xsl:value-of select="element2" /></td>
<td><xsl:value-of select="element3" /></td>
<td><xsl:value-of select="element4" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
This will produce the table nicely, but what about the
<link>
<title>Title of the URL link</title>
<url>http://some.url.link</url>
</link>
structure I have in my XML file? I would like to be able to put such a
link structure inside any element I have in the XML record. The link
structure itself is easily enough translated into a URL with an XSL
transformation of
(XSL2)
<xsl:template match="//link">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="url" />
</xsl:attribute>
<xsl:value-of select="title" />
</xsl:element>
</xsl:template>
But when I want to have the possibility of having URL links anywhere in
my HTML table, straight combining of (XSL1) and (XSL2) templates
fails...seems to have something to do with using the value-of structure
in (XSL1)...?
Regards,
Jyrki Keisala
<document>
<record>
<element1>Text</element1>
<element2>More text</element2>
<element3>Even more text</element3>
<element4>Some text <link><title>Google</title><url>
http://www.google.com</url></link> with a link.</element4>
</record>
<record>
<element1>Yeah</element1>
<element2>Now the link is here: <link><title>W3C</title><url>
http://www.w3c.org</url></link></element2>
<element3>Something else</element3>
<element4>...and more text</element4>
</record>
</document>
which I want to convert to an HTML table. One possibility for the
conversion is to use for-each loop in XSL as in
(XSL1)
<xsl:template match="/">
<html>
<head>
<title>My HTML table</title>
</head>
<body>
<table border="1">
<head>
<tr>
<td><b>Element1</b></td>
<td><b>Element2</b></td>
<td><b>Element3</b></td>
<td><b>Element4</b></td>
</tr>
</head>
<xsl:for-each select="document/record">
<tr>
<td><xsl:value-of select="element1" /></td>
<td><xsl:value-of select="element2" /></td>
<td><xsl:value-of select="element3" /></td>
<td><xsl:value-of select="element4" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
This will produce the table nicely, but what about the
<link>
<title>Title of the URL link</title>
<url>http://some.url.link</url>
</link>
structure I have in my XML file? I would like to be able to put such a
link structure inside any element I have in the XML record. The link
structure itself is easily enough translated into a URL with an XSL
transformation of
(XSL2)
<xsl:template match="//link">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="url" />
</xsl:attribute>
<xsl:value-of select="title" />
</xsl:element>
</xsl:template>
But when I want to have the possibility of having URL links anywhere in
my HTML table, straight combining of (XSL1) and (XSL2) templates
fails...seems to have something to do with using the value-of structure
in (XSL1)...?
Regards,
Jyrki Keisala