So I want to make an XSLT that would transform any XML following the rule:
<root1>
<elem1>text</elem1>
<elem2>text</elem2>
...
<elemx>text</elemx>
...
<image>someimgreference</image
<linkref>alink</linkref>
</root1>
<root2>
<elem1>text</elem1>
<elem2>text</elem2>
...
<elemx>text</elemx>
...
<image>someimgreference</image
<linkref>alink</linkref>
</root2>
using the XSLT I would get a table with the titles and when I have text, I only show the text, when I have image link I get the actual image with
<xsl:template match="image">
<img src="{@url}" />
</xsl:template>
or something and when I have a linkref, I just post the click-able link
root1/root2 is just an exemple... those could be any names, same goes for elem1/2/3/... I want the xslt to work with any XML with that structure. So no element name references.
HTML table would look like:
elem1 | elem2 |... |image|linkref
------------------------------------
text | text |... |photo|link
text | text |... |photo|link
I found some good references online but none really helped me get the table or none were generic enough. Is it possible what I want? Or how close can I get to getting this generic xslt?
This is the most generic I've found. I just need the image links to be shows as actual photos and link references to click-able links
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<BODY>
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="/*">
<TABLE BORDER="1">
<TR>
<xsl:for-each select="*[position() = 1]/*">
<TD>
<xsl:value-of select="local-name()"/>
</TD>
</xsl:for-each>
</TR>
<xsl:apply-templates/>
</TABLE>
</xsl:template>
<xsl:template match="/*/*">
<TR>
<xsl:apply-templates/>
</TR>
</xsl:template>
<xsl:template match="/*/*/*">
<TD>
<xsl:value-of select="."/>
</TD>
</xsl:template>
</xsl:stylesheet>
I don't know where to insert the image template or the link templates (or how to write the link template) I tried inserting it like a normal template and it doesn't work. It won't do anything with the link. Not to mention the clickable one... Any ideas? At all?
<xsl:template match="image"> <img src="{@url}" /> </xsl:template>looks good as long as theimageelements have aurlattribute, again your input sample does not show any such attribute.