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 August 9th, 2006, 05:29 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default cannot 'seek' inside a function

Hi,

i have the following : Blocks contain properties and can be nested. There is a tag called BlockParameterDefaults that contain default properties for each Block

<BlockParameterDefaults>
  <Block>
    <property name="BlockType" value="Gain" />
    <property name="gain" value="1.00" />
  </Block>

  <Block>
    <property name="BlockType" value="Sum" />
    <property name="Inputs" value="2" />
  </Block>
   ...
</BlockParameterDefaults>

and then :

  <Block>
    <property name="BlockType" value="Gain" />
    <property name="Name" value="my_Gain" />
  </Block>

what i want to do is to lookup for some property inside a Block, and when it is not found, get its value from BlockParameterDefaults. I know how to do that and i wrote a function :

<!-- lookup for a property and returns its value. If the property is not found in the current block, try to look for it in the <BlockParameterDefaults> under /Model
    -->
    Ã‚ Â
  <xsl:function name="mdl2sig:lookup_property">
    <xsl:param name="block_node" />
    <xsl:param name="property_name" />

    <xsl:choose>
    Ã‚  <xsl:when test="$block_node[property[@name=$property_name]]">
        <xsl:value-of select="$block_node/property[@name=$property_name]/@value" />
    Ã‚  </xsl:when>
    Ã‚  <xsl:otherwise>
        <xsl:value-of select="/*[position()=1]/BlockParameterDefaults/Block[property[@name='BlockType' and @value=$block_node/property[@name='BlockType']]/@value]/property[@name=$property_name]/@value" />
    Ã‚  </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

but the processor tells : XPDY0002: Cannot select a node here: the context item is undefined

(it refers to the otherwise clause).

It seems logical because functions don't have contexts, but here i'm selecting a node with an absolute path, it should work, shoulnd't it ?

<BlockParameterDefaults> is always located under /Model or /Library
'/' = root

Thanks
 
Old August 9th, 2006, 03:39 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The term "absolute path" is misleading and is not used in XPath 2.0, because it's not absolute at all, it's relative to the root node of the current document. The function needs to be given a parameter that tells it which document to look within, and the path needs to start $doc/...

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 10th, 2006, 01:54 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thank you again. I'll try to pass the appropriate parameter.






Similar Threads
Thread Thread Starter Forum Replies Last Post
TRANSLATE FUNCTION INSIDE XPATH pallone XSLT 8 February 8th, 2008 05:30 PM
Seek Time... ankur_icfai SQL Server 2000 2 August 30th, 2006 11:14 PM
How to call normal "write" function inside a class jonen C++ Programming 3 May 25th, 2006 02:19 PM
use a JS-variable/function inside a tag cybermaarten Javascript 3 January 20th, 2005 05:42 AM
Prb with js function call inside flash using XSL schander10 XSLT 3 September 14th, 2004 07:33 AM





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