Altova Mailing List Archives


Re: Is there a way to assign a node to a variable in such condition?

From: "Han" <hp4444@------.---.----->
To: NULL
Date: 8/24/2004 9:54:00 PM
I happened to discover a short example in xml 4.0 sdk. If you have xml like,

<a/>

This xslt, which can be applied to the xml, may show you an usage of copy-of
within variable.

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

<msxsl:script language="JScript" implements-prefix="user">
   function xml(nodelist) {
      return nodelist.nextNode()
   }
</msxsl:script>

<xsl:template match="/">
<xsl:variable name='v'>
        <xsl:copy-of select="user:xml(a)"/>
</xsl:variable>
<x>
        <xsl:copy-of select='$v'/>
</x>
</xsl:template>

</xsl:stylesheet>

The result should be something like this except a namespace because I didn't
use exclude-result-prefixes.

<x><a/></x>

"Han" <hp4444@k...> wrote in message
news:uE5CKcbiEHA.2668@T......
> Node is a subclass of nodeset. So if you want a node as a value of a
> variable, copy-of will do. Have you at least tried? If problem persists,
> show us a simplifed example please.
>
> "davidw" <davidw@a...> wrote in message
> news:uAg4QTbiEHA.3320@T......
> > No, copy-of doesn;t work, it says the expression should result in a
> nodeset.
> > I am still not sure how copy-of exactly does.
> >
> >
> > "Han" <hp4444@k...> wrote in message
> > news:%23dhFRwaiEHA.1652@T......
> > > Try copy-of instead of value-of if you want node as value of the
> variable
> > > and the function myextfunc returns node either.
> > >
> > > "davidw" <davidw@a...> wrote in message
> > > news:eKlp1kXiEHA.1280@T......
> > > > I can assign a node to a variable by
> > > >
> > > > <xsl:variable name="testnode" select="myprefix:myextfunc()"/>
> > > >
> > > > but in some case, I need get different node by different condition,
so
> > > > something like this will be perfect
> > > >
> > > > <xsl:variable name="testnode">
> > > >  <xsl:choose>
> > > >   <xsl:when test="$cond1=1"><xsl:value-of
> > > > select="myprefix:myextfunc1()"/></xsl:when>
> > > >   <xsl:when test="$cond1=2"><xsl:value-of
> > > > select="myprefix:myextfunc2()"/></xsl:when>
> > > >  </xsl:choose>
> > > > </xsl:variable>
> > > >
> > > > it obviously doesn;t work, since value-of returns a string, not a
> node.
> > > Does
> > > > anyone know how to assign a node to a variable in condition
statement?
> > > >
> > > > Thanks!
> > > >
> > > >
> > >
> > >
> >
> >
>
>


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.