Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Passing a Node to C# code in XSLT

From: "Joe Fawcett" <joefawcett@----------.------>
To: NULL
Date: 10/1/2005 7:00:00 AM
Greg

For my interest what did you need that couldn't be done via pure XSLT?
I am compiling a few use cases for scripting following some questions from 
Microsoft.

-- 

Joe

"Greg Collins [InfoPath MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message 
news:uaRFIwcxFHA.3400@T......
Solved!

I can only use XPathNodeIterator, as XPathNavigator is not allowed. It took a 
little playing, but here's how it worked:

    Param1.MoveNext();
    System.Xml.XPath.XPathNodeIterator Node = Param1.Current.Select(XPath);
    Node.MoveNext()
    return Node.Current.Value;

Wow! What a convoluted mess! It is incredible how painful that was... not very 
intuitive at all. But at least I got it working!

Thanks, Martin, for your help... it got me digging around a bit more.

-- 
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



"Martin Honnen" <mahotrash@y...> wrote in message 
news:O6GsfRcxFHA.2932@T......


Greg Collins [InfoPath MVP] wrote:

> I've run into a problem... I have an XSLT file that needs to get a
> value that is more complex than can be done in XSLT as the results
> will vary greatly depending on a second node value.
>
> This is all being run on an ASPX page.
>
> What I'm attempting to do is to pass a node into some C# code, and
> use that to get a child node depending on the value of a second
> parameter.
>
> When I pass in the node, I am not getting an XmlNode, nor an
> XmlDocument, XmlNodeList, etc.

The XPath/XSLT data model is different from the DOM data model and in
.NET there are certainly different classes and interfaces used so forget
about XmlNode and its subclasses for that task.



> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:cs="C#">
>
> <msxsl:script language="C#" implements-prefix="cs"> <![CDATA[ private
> string MyCSharpFunction(Object Param1, string Param2) { // I want to
> be able to get Param1 as an XmlNode return
> Param1.GetType().ToString(); } ]]> </msxsl:script>
>
> <xsl:variable name="NodeToPassIn"
> select="document('MyExternalFile.xml')/RootNode" />
>
> <xsl:template match="/RootNode"> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="SomeNode"> <xsl:choose> <xsl:when
> test="@someAttribute != ''"> <a target="_blank"
> href="{cs:MyCSharpFunction($NodeToPassIn,
> @someAttribute)}">

XSLT 1.0 nows primitive types like number, string, boolean and then only
node sets and result tree fragments as object types.
Here are the docs that explain the .NET equivalent:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXslXslTransformClassTopic.asp>

The table in there about script in XSLT lists:

W3C Type Equivalent .NET Class
String (XPath) System.String
Boolean (XPath) System.Boolean
Number (XPath) System.Double
Result Tree Fragment (XSLT) System.Xml.XPath.XPathNavigator
Node Set (XPath) System.Xml.XPath.XPathNodeIterator

Your script functions will get arguments of those types and need to
operate with the APIs defined for those types:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNavigatorClassTopic.asp>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNodeIteratorClassTopic.asp>

-- 

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/ 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent