Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2011, 04:19 PM
Registered User
 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default set a context for relative XPath-expressions

Hi,
to generate XSLT-Stylesheets i need a generic solution to set a context for relative XPath-expressions (or not relative). I've used:
Code:
<xsl:variable name="context" select="//context"/>
<xsl:value-of select="$context/(relativeXPath)"/>
Almost every time it works very fine. But now i have a problem, if the relativeXPath includes some for-loops. For example:
XML:
Code:
<context>
	<node a="1"/>
	<node a="2"/>
</context>
<difContext/>
both templates below should do the same thing, but they don't.
this (not "generic" variant) works, like it should:
Code:
<xsl:template match="context">
	<xsl:copy-of select="for $i in 0 to 1 return node[@a>$i]"/>
</xsl:template>
it returns:
Code:
<node a="1"/><node a="2"/><node a="2"/>
But this "generic" variant copies just both <node>-elements:
Code:
<xsl:template match="difContext">
	<xsl:variable name="context" select="//context"/>
	<xsl:copy-of select="$context/(for $i in 0 to 1 return node[@a>$i])"/>
</xsl:template>
output:
Code:
<node a="1"/><node a="2"/>
i dont understand why!? is there a reason for this difference? is there a workaround?
(i use oXygen 12.0 with Saxon-PE 9.2.1.2 on Win 7)
thanks for help!
 
Old March 8th, 2011, 08:22 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The "/" operator causes nodes to be sorted into document order with duplicates eliminated. It does more than just setting the context for evaluation of the rhs. You might be better off using xsl:for-each to do that.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Do Relative xPath In CustomXMLNode? johnywhy XML 0 January 3rd, 2011 12:23 AM
Xpath expressions with attributes rbooth XSLT 3 November 11th, 2007 04:51 AM
relative XPath references chroniclemaster1 XSLT 6 September 27th, 2007 01:16 AM
.net XPath expressions arcuza XSLT 1 December 1st, 2005 09:33 AM
Regular Expressions in XPath sonicDace XML 0 February 12th, 2004 05:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.