homepage Welcome to WebmasterWorld Guest from 54.161.192.130
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Assign link to Title
Change hyperlink
Marshall

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3367526 posted 2:57 pm on Jun 14, 2007 (gmt 0)

Simply put, I want the link to be like in HTML with <a href="">LINKING TEXT</a>, but all I can do is get the displayed URL to link.


<?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

 

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3367526 posted 5:15 pm on Jun 14, 2007 (gmt 0)

<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.

Marshall

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3367526 posted 10:28 pm on Jun 14, 2007 (gmt 0)

cmarshall,

Any help would be appreciated. I searched W3 schools, the web, WMforum, and found nothing useful. I am sure the answer is simple and obvious, but darn if I can find it.

Thanks in advance,
Marshall

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3367526 posted 10:54 pm on Jun 14, 2007 (gmt 0)

I have a bit of time now.

Do you have an example of the XML file you're trying to transform and what the desired result should be?

Marshall

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3367526 posted 11:04 pm on Jun 14, 2007 (gmt 0)

Here's the XML file. I replaced the URI's with the word LINK


<?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 &amp; Site Sponsor Ads Until 2008</description>
<category>Promotions</category>
</item>
<item>
<title>Lighting Equipment &amp; 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 &amp; 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

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3367526 posted 11:25 pm on Jun 14, 2007 (gmt 0)

Okay, here you go (see below).

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 &amp; Site Sponsor Ads Until 2008</description>
<category>Promotions</category>
</item>
<item>
<title>Lighting Equipment &amp; 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 &amp; 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>


Marshall

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3367526 posted 11:42 pm on Jun 14, 2007 (gmt 0)

cmarshall,

Works great. Much thanks. Will take serious look at the software you suggested.

Marshall

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3367526 posted 3:14 am on Jun 15, 2007 (gmt 0)

Will take serious look at the software you suggested.

What software suggested?

;)

Marshall

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3367526 posted 3:24 am on Jun 15, 2007 (gmt 0)

coopster,

I sent you a sticky

Marshall

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3367526 posted 3:30 am on Jun 15, 2007 (gmt 0)

I was just teasing about the big red text ;)

The recommendation has been made quite often so I think cmarshall was trying to make it more obvious this time ... obviously ;)

Just having some fun tonight, that's all!

Marshall

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3367526 posted 3:41 am on Jun 15, 2007 (gmt 0)

$$$$ helps too

;)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved