xslt: how can I fine-tune the href attribute of an anchor tag? RRS feed

  • Question

  • User846546683 posted

    I have a successful XSLT file (shown below), but what I'd like to do is adjust 

    <a href="{@url}">

    so that when when the transformed xml file appears in my asp:xml control on my aspx page, it appears as:

    <a href="<%# Page.ResolveClientURL(""{@url}"") %>">

    figured this wouldn't work, but this is the result I need. Is there some way to do this right?

    Here is the full xslt script, with the relevant line bolded:

    Thanks for any ideas.

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
        <xsl:output method="xml"  version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="yes" />
        <xsl:strip-space elements="*"/>   
        <xsl:template  match="map:siteMapNode">
                <a href="{@url}">
                    <xsl:value-of select="@title"/>
                <xsl:if test="map:siteMapNode">
                    <xsl:call-template name="mapNode"/>
        <xsl:template name="mapNode" match="map:siteMap">
                <xsl:when test="@*">
                        <xsl:apply-templates />
                    <ul id="">
                        <xsl:apply-templates />

    Sunday, May 3, 2015 11:58 PM


  • User846546683 posted

    The key isn't to do this in the XSLT document, but rather the ASP.NET page.

    <script runat="server">
        Public MenuList As String = String.Empty
        Protected Sub Page_Load(sender As Object, e As EventArgs)
            Dim ds As New DataSet()
            ' this for-each block resolves client URL
            For Each dr As DataRow In ds.Tables(0).Rows
                Dim tempURL As String = Page.ResolveClientUrl(dr("url").ToString)
                dr("url") = tempURL
            Dim strXML As String = ds.GetXml()
            MenuList = GetHtml(Server.MapPath("~/sitemap_static_3.xslt"), strXML)
        End Sub
        Public Shared Function GetHtml(xsltPath As String, xml As String) As String
            Dim stream As New MemoryStream(ASCIIEncoding.[Default].GetBytes(xml))
            Dim document As New XPathDocument(stream)
            Dim writer As New StringWriter()
            Dim transform As New XslCompiledTransform()
            transform.Transform(document, Nothing, writer)
            Return writer.ToString()
        End Function

    In the body: 

    <div id="content">
                    <a href='<%= Page.ResolveUrl("~/index.aspx")%>'>Homepage</a>
                <%= MenuList%>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 4, 2015 1:10 PM