Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a value returned from XML in a link

Status
Not open for further replies.

JasonHampson

Technical User
Feb 20, 2003
16
GB
I have a XSL template I’m creating and I want to insert a link to another web page. The name of the page is obtained from returning a value from an XML node.

I have tried both:

<xsl:template match=&quot;SUB_HEADING&quot;>

<A href=&quot;{concat(value-of select='MODULE',' - ',value-of select='HEADING','(',value-of select='ID',')','#',value-of select='TITLE','(',value-of select='ID',')')}&quot;><H3>Sub Heading:- <xsl:value-of select=&quot;HEADING&quot;/></H3></A>


</xsl:template>

which returns the function as a string and not something that is executed

and:

<xsl:template match=&quot;SUB_HEADING&quot;>

<A href=<xsl:value-of select=&quot;MODULE&quot;/> - <xsl:value-of select=&quot;HEADING&quot;/>(<xsl:value-of select=&quot;ID&quot;/>)#<xsl:value-of select=&quot;HEADING&quot;/>(<xsl:value-of select=&quot;ID&quot;/>)><H3>Sub Heading:- <xsl:value-of select=&quot;HEADING&quot;/></H3></A>


</xsl:template>

which gave an error saying a string literal was expected

If I put the above example in speech marks the error says I can’t use ‘<’ in an attribute.


Could anyone tell me how to solve my little problem
 
Use & l t ; and & g t ; (remove the spaces) in place of < and >.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
I changed the code to:

<xsl:template match=&quot;SUB_HEADING&quot;>

<A href='&lt;xsl:value-of select=&quot;MODULE&quot;/&gt;.xml'><H3>Sub Heading:- <xsl:value-of select=&quot;HEADING&quot;/></H3></A>


</xsl:template>


When I hovered my mouse over the link it says ‘file:///Q:/.../DCMS/<xsl:value-of select=”MODULE”>/>.xml’ and a page not found error occurs when I click on the link. I'm using Internet Explorer to translate the XML on the fly by referencing the style sheet in the XML header

 
Sorry i changed it to:

<xsl:template match=&quot;SUB_HEADING&quot;>

<A href='&l t;xsl:value-of select=&quot;MODULE&quot;/&g t;.xml'><H3>Sub Heading:- <xsl:value-of select=&quot;HEADING&quot;/></H3></A>


</xsl:template>

without the spaces in &l t; + &g t;
 
hi,

use xsl:variable to obtain the values, and then call the variable to the requisite template, if the method fails, please send the xml file, I will try my best to give the output.
 
When I used the <xsl:variable> function, internet explorer showed an error saying 'keyword xsl:variable may not be used here' in the below example:

<xsl:template match=&quot;SUB_HEADING&quot;>

<xsl:variable name=&quot;DocName&quot;><xsl:value-of select=&quot;MODULE&quot;/> - <xsl:value-of select=&quot;HEADING&quot;/>().xml</xsl:variable>

<A href='$DocName'><H3>Sub Heading:- <xsl:value-of select=&quot;HEADING&quot;/></H3></A>


</xsl:template>


The above code is meant to create a link to a file in the same directory whose file name comprises of 2 attributes obtained from an xml file. I can send sample code if it makes things any easier
 
Its ok I've solved it. The code i used was:

<H3><A><xsl:attribute name=&quot;href&quot;><xsl:value-of select=&quot;MODULE&quot;/> - <xsl:value-of select=&quot;HEADING&quot;/>().xml</xsl:attribute><xsl:value-of select=&quot;HEADING&quot;/></A></H3>

Quite simple after all of that
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top