XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Siarhei BarysiukSubject: xsl:key, scope and creating of variable
Author: Siarhei Barysiuk
Date: 31 Oct 2006 11:58 AM
Hello!

I have a one problem and searching in the internet doesn't help me.

XSL:
...
<xsl:variable name="$tagsDoc" select="document('external.xml')"/>
<xsl:key match="tag" name="tags" use="@name"/>

<xsl:template name="templ_name">

<!-- I would like to create a variable which contains a node from external xml -->
<xsl:variable name="tags">
<!-- change scope
for-each do one iteration-->
<xsl:for-each select="$tagsDoc">
<!-- in debug mode it's ok, key returns one node -->
<xsl:value-of select="key('tags','some_name')"/>
</xsl:for-each>
<!-- change scope
key() doesn't return any, because scope is changed
-->
</xsl:variable>
<!--variable is not initialized -->

</xsl:template>

Why cannot I define variable by this way? And does some way exist to define variable with node from external document by key()?

Thanks,
Siarhei Barysiuk

Postnext
Ivan PedruzziSubject: xsl:key, scope and creating of variable
Author: Ivan Pedruzzi
Date: 31 Oct 2006 06:17 PM
Hi Siarhei,

An half commented XSLT fragment is not enough to understand what you are trying to do.

If you want our help you have post a small working example XSLT + XML with a sample of the expected result.

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Siarhei BarysiukSubject: xsl:key, scope and creating of variable
Author: Siarhei Barysiuk
Date: 01 Nov 2006 08:42 AM
Hello Ivan,

For first thanks for reply.

I create small example:
- processor.xsl
- main.xml
- tags.xml

In example creating of variable will occur one time but in my project I need read extenal file many times and I decide that use of key() increases performance (I think it will be faster than direct select particular node through select="document('some_name')/tags/tag[.....]/@args" ).

Thanks,
Siarhei Barysiuk


Unknownexample.zip
Example

Postnext
James DurningSubject: xsl:key, scope and creating of variable
Author: James Durning
Date: 01 Nov 2006 11:23 AM
The answer to your problem depends exactly on what you want to do.

If you want to loop through each of the tags in the external file, I suggest using <xsl:apply-templates select="document('tags.xml')"/>

--
If you only want to access the external file once, it may be better to use the variable like you have here: <xsl:variable name="$tagsDoc" select="document('external.xml')"/>
and use an node-set function when you want to access it later.

eg. with msxsl:
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
<xsl:value-of select="msxsl:node-set($tagsDoc)/tags/tag[@name='somevalue']"/>

or with exslt:
xmlns:exslt="http://exslt.org/common"
<xsl:value-of select="exslt:node-set($tagsDoc)/tags/tag[@name='somevalue']"/>

Using a node-set function is not necessary if you use XSLT 2.0.

Postnext
Siarhei BarysiukSubject: xsl:key, scope and creating of variable
Author: Siarhei Barysiuk
Date: 01 Nov 2006 11:39 AM
Hi,

Yes, if I would access to external file once or few times. With $tagsDoc variable and select from it all work perfect. But it's slow (I think slower than it would be with key). I would like to increase speed of processing.

Thanks,
Siarhei

Posttop
Siarhei BarysiukSubject: xsl:key, scope and creating of variable
Author: Siarhei Barysiuk
Date: 04 Nov 2006 05:29 AM
Hello,

I've resolve this problem by oneself. The main problem is xsl:value-of.
xsl:value-of return STRING but not NODE SET. In this example need to use xsl:copy-of which retun NODE SET.

The working example attached.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.