Is there a way to pass param array to xslt funtion in extended object of xsl? thanks.
Collapse
This topic is closed.
X
X
-
davidTags: None -
Oleg Tkachenko
Re: Is there a way to pass param array to xslt funtion in extendedobject of xsl? thanks.
You should pass it as XPathNodeIterat or. There is no array type in XPath
data model.
--
Oleg Tkachenko
XML Insider
-
david
Re: Is there a way to pass param array to xslt funtion in extended object of xsl? thanks.
Thanks for reply.
My problem is I am not sure how to combine several objects that include
string and XPath objects into one XPathNodeIterat or.
"Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:eeGtiTNuDH A.572@TK2MSFTNG P11.phx.gbl...[color=blue]
> You should pass it as XPathNodeIterat or. There is no array type in XPath
> data model.
> --
> Oleg Tkachenko
> XML Insider
> http://www.tkachenko.com/blog
>[/color]
Comment
-
Oleg Tkachenko
Re: Is there a way to pass param array to xslt funtion in extendedobject of xsl? thanks.
david wrote:
[color=blue]
> My problem is I am not sure how to combine several objects that include
> string and XPath objects into one XPathNodeIterat or.[/color]
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(s w);
w.WriteStartEle ment("root");
for (int i=0; i<10; i++)
w.WriteElementS tring("val", "value"+i);
w.WriteEndEleme nt();
w.Close();
//XmlNodeWriter should be used instead of temporary string
XPathDocument doc = new XPathDocument(n ew StringReader(sw .ToString()));
XPathNavigator nav = doc.CreateNavig ator();
XsltArgumentLis t args = new XsltArgumentLis t();
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:styleshe et 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
Comment
-
david
Re: Is there a way to pass param array to xslt funtion in extended object of xsl? thanks.
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!P LEASEtkachenko. com> wrote in message
news:u4BcOWYuDH A.2244@TK2MSFTN GP09.phx.gbl...[color=blue]
> david wrote:
>[color=green]
> > My problem is I am not sure how to combine several objects that include
> > string and XPath objects into one XPathNodeIterat or.[/color]
>
> 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(s w);
> w.WriteStartEle ment("root");
> for (int i=0; i<10; i++)
> w.WriteElementS tring("val", "value"+i);
> w.WriteEndEleme nt();
> w.Close();
> //XmlNodeWriter should be used instead of temporary string
> XPathDocument doc = new XPathDocument(n ew StringReader(sw .ToString()));
> XPathNavigator nav = doc.CreateNavig ator();
> XsltArgumentLis t args = new XsltArgumentLis t();
> 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:styleshe et 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
>[/color]
Comment
-
Oleg Tkachenko
Re: Is there a way to pass param array to xslt funtion in extendedobject of xsl? thanks.
david wrote:
[color=blue]
> 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.[/color]
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
Comment
-
Hello,
I'm trying to send a XPathNodeIterat or as xsl: param into a template:
the node set delivered by the iterator looks like this:
<childEntitie s parentEntity="A ParentEntity">
<!-- child entities for AParentEntity -->
<entity name="aChildEnt ity" namespace="name space.of.aChild Entity" table="aChildEn tityTable" />
</childEntities>
the param name is ChildEntities and is added to an XsltArgumentLis t used by an XslCompiledTran sform. I'm using .NET 2.0.
Inside the xslt template, the param is defined this way:
<xsl: param name="ChildEnti ties" />
However, this script does not produce anything:
<xsl: for-each select="$ChildE ntities" >
// childentity
<xsl: copy-of select="."/>
</xsl:for-each>
:confused:
What is to be done?
Thank you,
DanComment
Comment