Q

How can I call my link from an XML tag?

The XML document below is called pressinfo.xml:

<?xml version='1.0'?>
<press_info>
<press>
<pressDate>Tue 10 Sep, 2002</pressDate>
<pressDetail>This Is A Test Xyz</pressDetail>
<presslink>/press/Newpress.asp?itemcode=478</presslink>
</press>
<press>
<pressDate>Tue 10 Sep, 2002</pressDate>
<pressDetail>New Press Release Testing</pressDetail>
<presslink>/press/Newpress.asp?itemcode=477</presslink>
</press>
<press>
<pressDate>Mon 22 Sep, 2002</pressDate>
<pressDetail>Xml Final Testing Page </pressDetail>
<presslink>/press/Newpress.asp?itemcode=472</presslink>
</press>
<press>
<pressDate>Mon 22 Sep, 2002</pressDate>
<pressDetail>This Is A Test 22 July</pressDetail>
<presslink>/press/Newpress.asp?itemcode=471</presslink>
</press>
<press>
<pressDate>Wed 17 Sep, 2002</pressDate>
<pressDetail>Xml Final </pressDetail>
<presslink>/press/Newpress.asp?itemcode=464</presslink>
</press>
</press_info>

My XSL document below is called press_default.xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--TEMPLATE RULE FOR ROOT ELEMENT-->
	<xsl:template match="/">
		<html>
		<body>
		<br/><br/>
			<xsl:call-template name="check"/>
		</body>
		</html>
	</xsl:template>
<xsl:template name="check">

<table border="0" cellpadding="2" cellspacing="0" 
width="100%">
<tr bgcolor="#cccccc"><font face="verdana" size="2">
	<td  
bgcolor="#cccccc"><b>Headline</b></td>
	<td  
bgcolor="#cccccc"><b>Date</b></td>
	</font>
</tr>
<xsl:for-each select="//press">
	<tr>
		<td width="60%">	
			<font face="verdana" size="2">
				<xsl:value-of 
select="pressDetail" />
			</font>
		</td>
		<td width="40%" valign="top">
			<font face="verdana" size="2">
				<xsl:value-of select="pressDate" 
/>
			</font>
		</td>
		
	</tr>		
	</xsl:for-each>
<tr>
	<td colspan="2"><br/></td>
</tr>
</table>
<table width="100%">	
<tr>
	<td colspan="2"><a href="/press"><font 
face="verdana" size="2">more press releases 
>></font></a></td>
</tr>	
</table>	
</xsl:template>
</xsl:stylesheet>

And the document below for transforming XML w/XSL is called pressxml2.asp:

<%	'Load into a DOM document
		
		'Dim DomDocLoc
		DomDocLoc=Server.MapPath("/includes/XMLFiles/pressinfo.xml")
		'Dim DomDoc
		Set DomDoc  = 
Server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
		DomDoc.Async=False
		DomDoc.Load DomDocLoc

		'Load the style sheet into a DOM document
		'Dim StyleDoc
		Set StyleDoc  = 
Server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
		StyleDocLoc=Server.MapPath("/includes/XMLStylesheet/press_default.xs
l")
		StyleDoc.Load StyleDocLoc
		
		'Transform and return to the browser for 
confirmation
		strOutput = DomDoc.TransformNode(StyleDoc)
		response.write strOutput

		'Destroy the object variables
		set styledoc=nothing
		set domdoc = nothing	
	
	
	%>

My problem is that I want to link the pressdetails to a specific page, ie. each pressDetails has a different page displaying the different press releases.

I tried putting the link into an XML tag called presslink. Is it possible to call it with the <a href="<xsl:value-of select="pressDetail" />">...something to that effect? I tried using that but it gives me errors. Any info with this problem would be appreciated.


The presslink element is definitely the way to go and you should have no difficulty extracting its value in the template. The trick is to use the value of the presslink element as the href attribute value. You need to do this in a way that keeps the XSL well-formed.

I suspect that the cause of your errors is that something like:

<a href="<xsl:value-of select="pressDetail" />">

is not well formed XML so the XSL processor will complain.


This was first published in September 2002

Dig deeper on XML and XML schema

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close