Welcome to MSDN Blogs Sign in | Join | Help

Love that ASP.NET and SQL Server

Ben Miller's Developer Experiences

XSLT vs. .NET 2.0 XML Framework

I have a project that I am wondering about using either XSLT or the .NET Framework 2.0 to transform an XML document into a table and then bind it. I know that I can bind XML in ways, but I am in a bind on this one and am more familiar with Framework coding in C# rather than XSLT.

I have run into a problem trying to get a URL into the xslt template using <a href=”something”>something</a> with the href being formed by part URL and part <xsl:value-of select=”something” />. It fails because I am not very good with it yet. Anyone with help or ideas, please feel free to suggest. I am going to go about it using .NET in C# and will entertain any XSLT help that anyone wants to provide.

I have been to www.topxml.com and www.xmlforasp.net and found some things that are basic, but nothing about how to use XSLT to put html elements together.

More to come as I finish this project.

Published Thursday, June 08, 2006 5:55 AM by benmiller

Comments

# re: XSLT vs. .NET 2.0 XML Framework @ Friday, June 09, 2006 12:03 PM

If you're generating HTML, you might take a look at Template Engine:
http://www.adersoftware.com/index.cfm?page=templateEngine2

works with .net 2 and is easy to use.

AD

# re: XSLT vs. .NET 2.0 XML Framework @ Friday, June 09, 2006 12:19 PM

Hi, Ben: Here's some code I had lying around that converts an XML element with location and title attributes into an HTML list item (<LI>) contain a href:

<xsl:template match="item">
 <LI>
 <A>
   <xsl:attribute name="HREF"><xsl:value-of select="@location" /></xsl:attribute>
   <xsl:attribute name="TITLE"><xsl:value-of select="@title" /></xsl:attribute>
   <xsl:value-of select="@title" />
 </A>
 </LI>
</xsl:template>

Phil Weber

# re: XSLT vs. .NET 2.0 XML Framework @ Friday, June 09, 2006 12:19 PM

Hi, Ben: Here's some code I had lying around that converts an XML element with location and title attributes into an HTML list item (<LI>) contain a href:

<xsl:template match="item">
 <LI>
 <A>
   <xsl:attribute name="HREF"><xsl:value-of select="@location" /></xsl:attribute>
   <xsl:attribute name="TITLE"><xsl:value-of select="@title" /></xsl:attribute>
   <xsl:value-of select="@title" />
 </A>
 </LI>
</xsl:template>

Phil Weber

# re: XSLT vs. .NET 2.0 XML Framework @ Sunday, June 11, 2006 3:53 PM

Did you try concat()?  I'm a bit rusty so the syntax may be a li'l off.

<a href="{concat($partUrl,'/',xpath-or-var-$something)}">something</a>

Grant Parks

# re: XSLT vs. .NET 2.0 XML Framework @ Monday, June 12, 2006 5:13 AM

You have to add the attribute explicitly, like this:

<a>
<xsl:attribute name="href">
<xsl:value-of select="websiteBaseURL">/yourpage.aspx
</xsl:attribute>
<xsl:value-of select="websiteBaseURL">/yourpage.aspx
</a>

chris@moneyexpert.com

# re: XSLT vs. .NET 2.0 XML Framework @ Monday, June 12, 2006 9:02 AM

You could pass in the "part URL" bit as an XSL parameter and then use concat($urlParam,"/",$vos) , where $vos has previously been evaluated to the required <xsl:value-of select=”something” />

Without seeing more details, I can't say if this is going to work, but it should be worth a try.

Good luck!

Michel

Michel Carroll

# re: XSLT vs. .NET 2.0 XML Framework @ Wednesday, June 21, 2006 1:04 PM

Try this:
<xsl:element name="elem">
<xsl:attribute name="href">
<xsl:text>URL</xsl:text>
<xsl:value-of select="something">
</xsl:attribute>
</xsl:element>

Greetings,
Tom

Tomasz Szalaj

Anonymous comments are disabled
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker