473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Is there a way to pass param array to xslt funtion in extended object of xsl? thanks.



Nov 12 '05 #1
7 15480
You should pass it as XPathNodeIterator. There is no array type in XPath
data model.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
Thanks for reply.

My problem is I am not sure how to combine several objects that include
string and XPath objects into one XPathNodeIterator.

"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ee*************@TK2MSFTNGP11.phx.gbl...
You should pass it as XPathNodeIterator. There is no array type in XPath
data model.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #3
david wrote:
My problem is I am not sure how to combine several objects that include
string and XPath objects into one XPathNodeIterator.


The easiest way is to build XmlDocument or XPathDocument, then ask it to
create XPathNavigator, select nodelist of values and pass it.
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.WriteStartElement("root");
for (int i=0; i<10; i++)
w.WriteElementString("val", "value"+i);
w.WriteEndElement();
w.Close();
//XmlNodeWriter should be used instead of temporary string
XPathDocument doc = new XPathDocument(new StringReader(sw.ToString()));
XPathNavigator nav = doc.CreateNavigator();
XsltArgumentList args = new XsltArgumentList();
args.AddParam("array", "", nav.Select("/root/*"));

XPathDocument input = new XPathDocument("foo.xml");
XslTransform xslt = new XslTransform();
xslt.Load("foo.xsl");
xslt.Transform(input, args, Console.Out);

foo.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:param name="array"/>
<xsl:template match="/">
<out>
<xsl:for-each select="$array">
<xsl:copy-of select="."/>
</xsl:for-each>
</out>
</xsl:template>
</xsl:stylesheet>

The result:
<out>
<val>value0</val>
<val>value1</val>
<val>value2</val>
<val>value3</val>
<val>value4</val>
<val>value5</val>
<val>value6</val>
<val>value7</val>
<val>value8</val>
<val>value9</val>
</out>
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4
Thanks for your reply.

I think what I am trying to do is calling a extension object in dll from
xsl, I need the way to pass parameters to functions in the extension object
when they were called from xsl.
"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:u4**************@TK2MSFTNGP09.phx.gbl...
david wrote:
My problem is I am not sure how to combine several objects that include
string and XPath objects into one XPathNodeIterator.


The easiest way is to build XmlDocument or XPathDocument, then ask it to
create XPathNavigator, select nodelist of values and pass it.
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.WriteStartElement("root");
for (int i=0; i<10; i++)
w.WriteElementString("val", "value"+i);
w.WriteEndElement();
w.Close();
//XmlNodeWriter should be used instead of temporary string
XPathDocument doc = new XPathDocument(new StringReader(sw.ToString()));
XPathNavigator nav = doc.CreateNavigator();
XsltArgumentList args = new XsltArgumentList();
args.AddParam("array", "", nav.Select("/root/*"));

XPathDocument input = new XPathDocument("foo.xml");
XslTransform xslt = new XslTransform();
xslt.Load("foo.xsl");
xslt.Transform(input, args, Console.Out);

foo.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:param name="array"/>
<xsl:template match="/">
<out>
<xsl:for-each select="$array">
<xsl:copy-of select="."/>
</xsl:for-each>
</out>
</xsl:template>
</xsl:stylesheet>

The result:
<out>
<val>value0</val>
<val>value1</val>
<val>value2</val>
<val>value3</val>
<val>value4</val>
<val>value5</val>
<val>value6</val>
<val>value7</val>
<val>value8</val>
<val>value9</val>
</out>
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #5
david wrote:
I think what I am trying to do is calling a extension object in dll from
xsl, I need the way to pass parameters to functions in the extension object
when they were called from xsl.


So, what's your problem actually? You can pass parameters to the
transformation and to exctension functions. But those parameters should
be only of fixed number of types. See
http://msdn.microsoft.com/library/de...ionobjects.asp

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #6
Hello,

I'm trying to send a XPathNodeIterator as xsl: param into a template:
the node set delivered by the iterator looks like this:

<childEntities parentEntity="AParentEntity">

<!-- child entities for AParentEntity -->
<entity name="aChildEntity" namespace="namespace.of.aChildEntity" table="aChildEntityTable" />

</childEntities>

the param name is ChildEntities and is added to an XsltArgumentList used by an XslCompiledTransform. I'm using .NET 2.0.

Inside the xslt template, the param is defined this way:
<xsl: param name="ChildEntities" />

However, this script does not produce anything:

<xsl: for-each select="$ChildEntities" >
// childentity
<xsl: copy-of select="."/>
</xsl:for-each>
:confused:

What is to be done?

Thank you,
Dan
Jul 3 '06 #7
Stupid me...
I was creating the XPathNodeIterator this way:
nav.Select( "/" ) instead of nav.Select( "/*" )
Jul 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
The following class method is being rejected by the PHP parser. If I change the method paramaters and allow the objects to be passed as copies, then the parser has no problem. Or, if I pass by...
12
by: Keith Chadwick | last post by:
I have a fairly hefty XSLT file that for the sake of debugging and clarity I wish to split into some separate sub-templates contained within the same file. The master template calls an...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
0
by: Daimy | last post by:
I meet the same problem below, please help me! Thanks! //written by some one I have developed a windows forms user control, which I am going to host in Internet Explorer.. I am familiar...
1
by: Dan Beanweed | last post by:
I have this xslt : <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="p" select="'q'"/> <xsl:output...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
2
by: arthuryeung198 | last post by:
Hi all, I got a JSP using JSTL to transform XML to HTML, and I want to pass a variable "statusFilter" into the XSL. e.g. <x:parse xml="${xml}" var="doc" /> <x:transform xml="${doc}"...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.