We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,624 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

using dynamic links

Hello there!
I am pretty new to xml and xsl. I have been trying to achive a dynamic link creation. My xml file has the format like;

<root>
<customer>company_name</customer>
<id>2334</id>
<code>xsTu4</code>
<mail>info@comany.com</mail>
</customer>
</root>

I want to use an XSL file to give me a link like detail.aspx?id=2334

I have tried

<xsl:value-of select="id"/>
 <a href="detay.aspx?id={id}">
 <xsl:value-of select="company"/>
                    </a>

but didnt get what i need:( I need a company name with a link:) so I can post it to details.aspx page with the company id.
I am using <xsl:for-each select="/root/customer"> to get all the information as well.

So? any idea?

2
Contributors
1
Reply
1 Week
Discussion Span
2 Years Ago
Last Updated
2
Views
Ceviz
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Well first off your input sample isn't well formed XML, so there's something wrong with the sample you've given.

However, if you're trying to build a string that looks like that, this transformation will work. I've modified your original input as well to make it work.

Input

<root>
	<customer>company_name
		<id>2334</id>
		<code>xsTu4</code>
		<mail>info@comany.com</mail>
	</customer>
</root>

XSLT Transformation

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<xsl:apply-templates select="root"/>
	</xsl:template>

	<xsl:template match="root">
		<xsl:element name="links">
			<xsl:apply-templates select="customer"/>
		</xsl:element>
	</xsl:template>

	<xsl:template match="customer">
		<xsl:element name="page">
			<a>
				<xsl:attribute name="href">
					<xsl:value-of select="concat('detail.aspx?id=',id)"/>
				</xsl:attribute>
			</a>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

This produces an output of the following.

<links>
	<page>
		<a href="detail.aspx?id=2334"/>
	</page>
</links>

Without more details, I can't really help much more.

iceandrews
Junior Poster
185 posts since May 2010
Reputation Points: 10
Solved Threads: 30
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0590 seconds using 2.69MB