Forum Moderators: open
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body style="font-family:arial">
<h2 style="color:#FFF;background-color:#000;border: thin solid #F90;padding: 2px">TEXT</h2>
<xsl:for-each select="news/item">
<xsl:sort select="category"/>
<p><xsl:apply-templates select="title"/> -
<xsl:value-of select="category"/><br />
<xsl:value-of select="description"/><br />
<xsl:apply-templates select="link"/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="title">
<span style="font-weight:bold;color:#009">
<xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="link">
<A style="font-size:.8em;">
<xsl:attribute name="HREF">
<xsl:apply-templates/>
</xsl:attribute>
<xsl:apply-templates/>
</A>
</xsl:template>
</xsl:stylesheet>
template match="link' is what is linking (and link is the holder of the URI) but I want the link to be the title. Make sense? Any help would be appreciated.
Marshall
<A style="font-size:.8em;">
<xsl:attribute name="HREF">
<xsl:apply-templates/>
</xsl:attribute>
<xsl:apply-templates/>
</A>
Should be:
<xsl:element name="a">
<xsl:attribute name="HREF">
<xsl:apply-templates/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
There may be some other issues, but I can't make enough time to give it a going-over yet.
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="news.xsl"?>
<news>
<item>
<title>Site News</title>
<link>LINK</link>
<description>Receive Half Off Page Sponsor & Site Sponsor Ads Until 2008</description>
<category>Promotions</category>
</item>
<item>
<title>Lighting Equipment & Supplies</title>
<link>LINK</link>
<description>BMI Supply, Lighting Equipment, Queensbury, NY</description>
<category>New Listing</category>
</item>
<item>
<title>Costume Designers</title>
<link>LINK</link>
<description>Catherine Fritsch, Costume Design & Construction, Cicero, IN</description>
<category>New Listing</category>
</item>
<item>
<title>Scenery Designers</title>
<link>LINK</link>
<description>RSL Theatrical scenic studio, Columbus, GA</description>
<category>New Listing</category>
</item>
<item>
<title>Updated Information</title>
<link>LINK</link>
<description>Textile Fabric Consultants, Inc. updated contact information</description>
<category>Listing Updates</category>
</item>
<item>
<title>Interns Sought</title>
<link>LINK</link>
<description>Midland (TX) Community Theatre seeks interns for multiple technical positions</description>
<category>Help Wanted</category>
</item>
</news>
With the XSL I provided earlier, the above displays:
TITLE
DESCRIPTION
[u]LINK[/u] - which is the actual link.
What I would like is similar to how this would display if it were RSS:
[u]TITLE[/u] - This text to be the link, the URI being located in the <link></link> tags of the XML, the URI not displayed
DESCRIPTION.
Make sense?
Marshall
Now, I'll say what I always say:
If you want to play in the XSLT pool, you NEED a tool like <oXygen/>, Stylus Studio or XMLSpy.
I used <oXygen/> to whip this up in about 10 minutes.
Your XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="news.xsl"?>
<news>
<item>
<title>Site News</title>
<link>http://www.example.com/link1</link>
<description>Receive Half Off Page Sponsor & Site Sponsor Ads Until 2008</description>
<category>Promotions</category>
</item>
<item>
<title>Lighting Equipment & Supplies</title>
<link>http://www.example.com/link2</link>
<description>BMI Supply, Lighting Equipment, Queensbury, NY</description>
<category>New Listing</category>
</item>
<item>
<title>Costume Designers</title>
<link>http://www.example.com/link3</link>
<description>Catherine Fritsch, Costume Design & Construction, Cicero, IN</description>
<category>New Listing</category>
</item>
<item>
<title>Scenery Designers</title>
<link>http://www.example.com/link4</link>
<description>RSL Theatrical scenic studio, Columbus, GA</description>
<category>New Listing</category>
</item>
<item>
<title>Updated Information</title>
<link>http://www.example.com/link5</link>
<description>Textile Fabric Consultants, Inc. updated contact information</description>
<category>Listing Updates</category>
</item>
<item>
<title>Interns Sought</title>
<link>http://www.example.com/link6</link>
<description>Midland (TX) Community Theatre seeks interns for multiple technical positions</description>
<category>Help Wanted</category>
</item>
</news>
The XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/><xsl:template match="/">
<xsl:for-each select="/news/item">
<xsl:call-template name="news_item"/>
</xsl:for-each>
</xsl:template><xsl:template name="news_item">
<div class="news_item_div">
<div class="news_item_div_header">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>
</div>
<div class="news_item_div_description">
<xsl:value-of select="description"/>
</div>
</div>
</xsl:template>
</xsl:stylesheet>