|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: variable nodelist travarse how??
Hi Tareq,
> I have a variable declaerd as:
>
> <xsl:variable name="varNodepkli">
> <xsl:for-each select="$abc">
>
> <xsl:element name="pkli">
> <xsl:attribute name="pkli_oid">
> <xsl:value-of select="@pkli_oid" />
> </xsl:attribute>
>
> <xsl:attribute name="pkli_ositem">
> <xsl:value-of select="@pkli_ositem" />
> </xsl:attribute>
>
> <xsl:attribute name="pkli_clsz">
> <xsl:value-of select="@pkli_clsz" />
> </xsl:attribute>
>
> <xsl:attribute name="pkli_colr">
> <xsl:value-of select="@pkli_colr" />
> </xsl:attribute>
>
> <xsl:attribute name="pkli_size">
> <xsl:value-of select="@pkli_size" />
> </xsl:attribute>
>
> <xsl:attribute name="pkli_qnty">
> <xsl:value-of select="@pkli_qnty" />
> </xsl:attribute>
> </xsl:element>
> </xsl:for-each>
> </xsl:variable>
You could make that a lot shorter:
<xsl:variable name="varNodepkli">
<xsl:for-each select="$abc">
<pkli>
<xsl:copy-of select="@pkli_oid | @pkli_ositem | @pkli_clsz |
@pkli_colr | @pkli_size | @pkli_qnty" />
</pkli>
</xsl:for-each>
</xsl:variable>
> Then i called a template as:
>
> <xsl:call-template name="pkliAdd">
> <xsl:with-param name="pk" select="$varNodepkli"/>
> </xsl:call-template>
OK, so here you pass in the result tree fragment to the pkliAdd
template.
> The template needs to travarse by recursion all the pkli nodes in the
> variable. So i tried
>
> <xsl:template name="pkliAdd">
>
> <xsl:param name="pk"/>
> <xsl:choose>
> <xsl:when test="$pk">
>
> <xsl:element name="pkli">
> <xsl:attribute name="pkli_oid">
> <xsl:value-of
> select="msxsl:node-set($pk)/pkli/@pkli_oid" />
> </xsl:attribute>
> </xsl:element>
>
> <xsl:call-template name="pkliAdd">
> <xsl:with-param name="pk" select="following-sibling::$pk"/>
> </xsl:call-template>
>
> </xsl:when>
>
> <xsl:otherwise>
>
> </xsl:otherwise>
>
> </xsl:choose>
> </xsl:template>
First, is there any particular reason why you want to traverse the
pkli nodes by recursion? If not, then you'd be better off traversing
them by iteration, using xsl:for-each:
<xsl:template name="pkliAdd">
<xsl:param name="pk" />
<xsl:for-each select="msxsl:node-set($pk)/pkli">
<pkli pkli_oid="{@pkli_oid}" />
</xsl:for-each>
</xsl:template>
although if that's what you want to generate, I'm not sure why you're
bothering with the variable in the first place.
If you do want to traverse by recursion for some reason, then you need
to think about what $pk gets set to. At the moment you're initially
setting it to the result tree fragment. It sounds as though you'd be
better off setting it to a pkli element:
<xsl:call-template name="pkliAdd">
<xsl:with-param name="pk"
select="msxsl:node-set($varNodepkli)/pkli"/>
</xsl:call-template>
Then you can do:
<xsl:template name="pkliAdd">
<xsl:param name="pk"/>
<xsl:choose>
<xsl:when test="$pk">
<pkli pkli_oid="{$pk/@pkli_oid}" />
<xsl:call-template name="pkliAdd">
<xsl:with-param name="pk" select="$pk/following-sibling::pkli"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Note that following-sibling::$pk isn't good XPath syntax. If you want
the following sibling pkli element of the node held in the $pk
variable, then you need:
$pk/following-sibling::pkli
as above.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








