[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

SV: Strange Parameter Behavior

Subject: SV: Strange Parameter Behavior
From: "bryan" <bry@xxxxxxxxxx>
Date: Fri, 10 May 2002 09:22:14 +0200
c default parameter value

-----Oprindelig meddelelse-----
Fra: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] På vegne af David N
Bertoni/Cambridge/IBM
Sendt: 10. maj 2002 00:03
Til: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Emne: Re:  Strange Parameter Behavior



Michael Peet wrote:
> Given the XML:
>
> <a id="1">
>   <b id="2">
>     <c id="3"/>
>     <c id="4"/>
>     <c id="5"/>
>     <c id="6"/>
>   </b>
>   <b id="7">
>     <c id="8"/>
>     <c id="9"/>
>     <c id="10"/>
>   </b>
>   <b id="11">
>     <c id="12"/>
>     <c id="13"/>
>     <c id="14"/>
>   </b>
> </a>
>
>
> And XSLT of:
>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:output encoding="ascii" omit-xml-declaration="yes"
indent="yes"/>
>   <xsl:strip-space elements="*"/>
>
>   <xsl:param name="param-id" select="/a/b/c[1]/@id"/>
>
>   <xsl:template match="/">
>     param-id: <xsl:value-of select="$param-id"/><br/>
>     prev: <xsl:value-of select="//c[@id
= $param-id]/preceding::c[1]/@id"/><br/>
>     next: <xsl:value-of select="//c[@id
= $param-id]/following::c[1]/@id"/><br/>
>   </xsl:template>
>
> </xsl:stylesheet>
>
>
> I get the following expected results when passing in a parameter:
>
> param-id: 12
> prev: 10
> next: 13

Well, since you didn't provide the value the parameter, we'll have to
take your word that the result is expected.

> However, when I don't pass anything in and let the default parameter 
> take

> over, I get this output:
>
> param-id: 3
> prev: 6
> next: 4
>
> Could anyone explain this?  Is there a RTF at work here?  When I wrap 
> the

> default parameter value with a string() function, the stylesheet 
> returns
the
> expected results:
>
> param-id: 3
> prev:
> next: 4

The results you got are correct, and there is no RTF involved.  I can
think of several things that might be confusing you.  One is the
existential quantification of the = operator when a node-set is one of
the operands. The other is that the preceeding axis is a
reverse-document-order axis, so the predicate [1] may not give you what
you expect.  Since wrapping the default parameter value in a call to the
string() function gives you what you expect, you're probably getting
tripped up by the behavior of the = operator.  (The string() function
will return the string value of the first node in the node-set.)

Try this variation on your template:

  <xsl:template match="/">
    param-id: <xsl:value-of select="$param-id"/><br/>
    count: <xsl:value-of select="count($param-id)"/><br/>
    prev: <xsl:value-of select="//c[@id
= $param-id]/preceding::c[1]/@id"/><br/>
    prev with $param-id predicate: <xsl:value-of select="//c[@id =
$param-id[1]]/preceding::c[1]/@id"/><br/>
    next: <xsl:value-of select="//c[@id
= $param-id]/following::c[1]/@id"/><br/>
  </xsl:template>

Hope that helps...

Dave



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.