Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Passing a Node to C# code in XSLT [Thread Next] Re: Passing a Node to C# code in XSLTTo: NULL Date: 10/4/2005 11:51:00 AM I have an XML file with link templates. Each template has an id and a =
url... so I could have a template like this:
<Template id=3D"abcd" url=3D"http://someserver.foo/folder/{0}/{1}#{2}"/>
or something like that. Each url might have a different number of =
parameters...
Now your probably saying... well you can do this in XSLT... just use an =
xsl:choose construct and a series of translate() functions. True. You =
can do it that way. But I didn't want to have to hastle with all of =
those there.
Instead I just create a single link:
<a target=3D"_blank" href=3D"{cs:TemplateLink($Templates, =
@url)}"><xsl:copy-of select=3D"."/></a>
This way my XSL is cleaner and I can use C#'s string.Format() function. =
I can also do other comlplex things when filling in the parameters as C# =
is a lot more powerful than the few functions you get in XSLT.
Anyway... that was the idea behind it. I still don't understand why I =
can't get an XmlNode object back from an XPathNodeIterator -- I can get =
the node value, just not the node itself -- but at least it is working =
now.
--=20
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
"Joe Fawcett" <joefawcett@n...> wrote in message =
news:#HuqyApxFHA.3860@T......
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=20
Microsoft.
--=20
Joe
"Greg Collins [InfoPath MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in =
message=20
news:uaRFIwcxFHA.3400@T......
Solved!
I can only use XPathNodeIterator, as XPathNavigator is not allowed. It =
took a=20
little playing, but here's how it worked:
Param1.MoveNext();
System.Xml.XPath.XPathNodeIterator Node =3D =
Param1.Current.Select(XPath);
Node.MoveNext()
return Node.Current.Value;
Wow! What a convoluted mess! It is incredible how painful that was... =
not very=20
intuitive at all. But at least I got it working!
Thanks, Martin, for your help... it got me digging around a bit more.
--=20
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
"Martin Honnen" <mahotrash@y...> wrote in message=20
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=3D"1.0" encoding=3D"UTF-8"?> <xsl:stylesheet =
version=3D"1.0"
> xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt" xmlns:cs=3D"C#">
>
> <msxsl:script language=3D"C#" implements-prefix=3D"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=3D"NodeToPassIn"
> select=3D"document('MyExternalFile.xml')/RootNode" />
>
> <xsl:template match=3D"/RootNode"> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match=3D"SomeNode"> <xsl:choose> <xsl:when
> test=3D"@someAttribute !=3D ''"> <a target=3D"_blank"
> href=3D"{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=3D/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=3D/library/en-us/cpref=
/html/frlrfSystemXmlXPathXPathNavigatorClassTopic.asp>
<http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/cpref=
/html/frlrfSystemXmlXPathXPathNodeIteratorClassTopic.asp>
--=20
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/=20
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
