Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 862743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:11:37+00:00 2026-05-15T09:11:37+00:00

I have an xslt stylesheet that needs to call a C# XSLT extension function

  • 0

I have an xslt stylesheet that needs to call a C# XSLT extension function in order to process a collection of elements. The code looks a little like this:

Xslt:

<xsl:apply-templates mode="MyTemplate" select="myextension:GetSomeCollection(@someattribute)" />
<xsl:template mode="MyTemplate" match="myroot">
  <xsl:value-of select="xpath" />...<xsl:value-of select="/xpath" />
</xsl:template>

Extension method:

public XPathNavigator GetSomeCollection(string Attribute)
{
    XmlDocument doc = new XmlDocument()
    //etc... 
    return doc.CreateNavigator();
}

The extension method returns a XPathNavigator as thats the only way I can see for an extension method to return any sort of collection.

The problem I’m having is that my template (the one with mode=”MyTemplate”) needs to be able to access xml nodes in the root / input document to the xslt stylesheet (as well as nodes in the node set returned by the extension method), however the template only seems to have access to the xml fragment returned by GetSomeCollection – xpath expressions starting / just resolve to the start of that fragment.

I can see why this is (the template is processing an xml fragment, however that fragment belongs to a different document), however I can’t see how to get around it. There doesn’t seem to be any way to get the extension method to produce an xml fragment belonging to the original document.

What can I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:11:38+00:00Added an answer on May 15, 2026 at 9:11 am

    Use a variable?

    <xsl:variable name="root" select="/"/>
    <xsl:template mode="MyTemplate" match="myroot">
      <xsl:value-of select="$root/..."/>
      <xsl:value-of select="xpath" />...<xsl:value-of select="/xpath" />
    </xsl:template>
    

    or a parameter:

    <xsl:apply-templates mode="MyTemplate"
           select="myextension:GetSomeCollection(@someattribute)">
      <xsl:with-param name="foo" select="...some local query..."/>
    </xsl:apply-templates>
    
    <xsl:template mode="MyTemplate" match="myroot">
      <xsl:param name="foo"/>
      <xsl:value-of select="$foo/..."/>
      <xsl:value-of select="xpath" />...<xsl:value-of select="/xpath" />
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xslt stylesheet with multiple xsl:import s and I want to merge
I have a Java servlet which generates XML, translates it with an XSLT stylesheet,
Does anyone have an XSLT that will take the app.config and render it into
We have one large xslt that renders a whole shop area including products, manifacturers
I have the following code block in my xslt; <xsl:when test=StatusData/Status/Temperature > 27> <td
I have an xslt sheet with some text similar to below: <xsl:text>I am some
I have an XSLT for viewing XML files in the browser. The XSLT is
i have some big xslt crashing iis (StackOverflowException) when loading an XslCompiledTransform while the
How to access App_Data folder in WCF service? I have placed a xslt file
i have this block of xslt if-else case and was wondering if there's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.