Transform a "String" to a nodeset

Transform a "String" to a nodeset

Post by Dominique MILLO » Thu, 26 Jun 2003 16:11:57



Hello,

<<Target>>
I'm looking for a kind of constant array in an XSL (with Asp.Net...).

<<My idea>>
Use a variable as NodeSet container :

  <xsl:variable name="Array">
   <Root>
    <Line Val="1" />
    <Line Val="2" />
    <Line Val="3" />
   </Root>
  </xsl:variable>

  <xsl:for-each select="$Array" > <!-- error: The expression passed to this
method should result in a NodeSet -->
    ......
  </xsl:for-each>

<<The error>>
For-each need an nodeset, but the variable contain a string...

<<Question>>
Did somebody have a solution?
Or an other way?
(My array will have more than one field, and will be use several times on a
same process)

Regards.

 
 
 

Transform a "String" to a nodeset

Post by Oleg Tkachenk » Thu, 26 Jun 2003 17:52:15



> <<My idea>>
> Use a variable as NodeSet container :

>   <xsl:variable name="Array">
>    <Root>
>     <Line Val="1" />
>     <Line Val="2" />
>     <Line Val="3" />
>    </Root>
>   </xsl:variable>

>   <xsl:for-each select="$Array" > <!-- error: The expression passed to this
> method should result in a NodeSet -->
>     ......
>   </xsl:for-each>

> <<The error>>
> For-each need an nodeset, but the variable contain a string...

No, the variable contains result-tree fragment.

Quote:> Did somebody have a solution?

Convert it to nodeset by msxsl:node-set() function.

Quote:> Or an other way?

Another way is to include the subtree directly to the stylesheet tree:
<xsl:stylesheet ... xmlns:foo="foo.bar">
     <foo:Root>
         <Line Val="1" />
         <Line Val="2" />
         <Line Val="3" />
     </foo:Root>
     <xsl:template ...
     ...

Then nodeset of Line elements can be accessible as document('')/*/foo:Root/*
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

 
 
 

Transform a "String" to a nodeset

Post by Colin Mackenzi » Thu, 26 Jun 2003 17:44:13


Hi

If you are using MSXML and you dont mind using non-portable extensions
(although several processors have this function) use node-set (returns a
node set from an XML string)

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">

    <xsl:for-each select="msxsl:node-set($Array)/Root/Line" >

    </xsl:for-each>

Colin


Quote:> Hello,

> <<Target>>
> I'm looking for a kind of constant array in an XSL (with Asp.Net...).

> <<My idea>>
> Use a variable as NodeSet container :

>   <xsl:variable name="Array">
>    <Root>
>     <Line Val="1" />
>     <Line Val="2" />
>     <Line Val="3" />
>    </Root>
>   </xsl:variable>

>   <xsl:for-each select="$Array" > <!-- error: The expression passed to
this
> method should result in a NodeSet -->
>     ......
>   </xsl:for-each>

> <<The error>>
> For-each need an nodeset, but the variable contain a string...

> <<Question>>
> Did somebody have a solution?
> Or an other way?
> (My array will have more than one field, and will be use several times on
a
> same process)

> Regards.